| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1 | // -*- C++ -*- | 
 | 2 | //===---------------------------- deque -----------------------------------===// | 
 | 3 | // | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 5 | // | 
| Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open | 
 | 7 | // Source Licenses. See LICENSE.TXT for details. | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 8 | // | 
 | 9 | //===----------------------------------------------------------------------===// | 
 | 10 |  | 
 | 11 | #ifndef _LIBCPP_DEQUE | 
 | 12 | #define _LIBCPP_DEQUE | 
 | 13 |  | 
 | 14 | /* | 
 | 15 |  deque synopsis | 
 | 16 |  | 
 | 17 | namespace std | 
 | 18 | { | 
 | 19 |  | 
 | 20 | template <class T, class Allocator = allocator<T> > | 
 | 21 | class deque | 
 | 22 | { | 
 | 23 | public: | 
 | 24 |  // types: | 
 | 25 |  typedef T value_type; | 
 | 26 |  typedef Allocator allocator_type; | 
 | 27 |  | 
 | 28 |  typedef typename allocator_type::reference reference; | 
 | 29 |  typedef typename allocator_type::const_reference const_reference; | 
 | 30 |  typedef implementation-defined iterator; | 
 | 31 |  typedef implementation-defined const_iterator; | 
 | 32 |  typedef typename allocator_type::size_type size_type; | 
 | 33 |  typedef typename allocator_type::difference_type difference_type; | 
 | 34 |  | 
 | 35 |  typedef typename allocator_type::pointer pointer; | 
 | 36 |  typedef typename allocator_type::const_pointer const_pointer; | 
 | 37 |  typedef std::reverse_iterator<iterator> reverse_iterator; | 
 | 38 |  typedef std::reverse_iterator<const_iterator> const_reverse_iterator; | 
 | 39 |  | 
 | 40 |  // construct/copy/destroy: | 
| Howard Hinnant | 009b2c4 | 2011-06-03 15:16:49 | [diff] [blame] | 41 |  deque() noexcept(is_nothrow_default_constructible<allocator_type>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 42 |  explicit deque(const allocator_type& a); | 
 | 43 |  explicit deque(size_type n); | 
| Marshall Clow | e00f53b | 2013-09-09 18:19:45 | [diff] [blame] | 44 |  explicit deque(size_type n, const allocator_type& a); // C++14 | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 45 |  deque(size_type n, const value_type& v); | 
 | 46 |  deque(size_type n, const value_type& v, const allocator_type& a); | 
 | 47 |  template <class InputIterator> | 
 | 48 |  deque(InputIterator f, InputIterator l); | 
 | 49 |  template <class InputIterator> | 
 | 50 |  deque(InputIterator f, InputIterator l, const allocator_type& a); | 
 | 51 |  deque(const deque& c); | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 52 |  deque(deque&& c) | 
 | 53 |  noexcept(is_nothrow_move_constructible<allocator_type>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 54 |  deque(initializer_list<value_type> il, const Allocator& a = allocator_type()); | 
 | 55 |  deque(const deque& c, const allocator_type& a); | 
 | 56 |  deque(deque&& c, const allocator_type& a); | 
 | 57 |  ~deque(); | 
 | 58 |  | 
 | 59 |  deque& operator=(const deque& c); | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 60 |  deque& operator=(deque&& c) | 
 | 61 |  noexcept( | 
 | 62 |  allocator_type::propagate_on_container_move_assignment::value && | 
 | 63 |  is_nothrow_move_assignable<allocator_type>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 64 |  deque& operator=(initializer_list<value_type> il); | 
 | 65 |  | 
 | 66 |  template <class InputIterator> | 
 | 67 |  void assign(InputIterator f, InputIterator l); | 
 | 68 |  void assign(size_type n, const value_type& v); | 
 | 69 |  void assign(initializer_list<value_type> il); | 
 | 70 |  | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 71 |  allocator_type get_allocator() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 72 |  | 
 | 73 |  // iterators: | 
 | 74 |  | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 75 |  iterator begin() noexcept; | 
 | 76 |  const_iterator begin() const noexcept; | 
 | 77 |  iterator end() noexcept; | 
 | 78 |  const_iterator end() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 79 |  | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 80 |  reverse_iterator rbegin() noexcept; | 
 | 81 |  const_reverse_iterator rbegin() const noexcept; | 
 | 82 |  reverse_iterator rend() noexcept; | 
 | 83 |  const_reverse_iterator rend() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 84 |  | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 85 |  const_iterator cbegin() const noexcept; | 
 | 86 |  const_iterator cend() const noexcept; | 
 | 87 |  const_reverse_iterator crbegin() const noexcept; | 
 | 88 |  const_reverse_iterator crend() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 89 |  | 
 | 90 |  // capacity: | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 91 |  size_type size() const noexcept; | 
 | 92 |  size_type max_size() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 93 |  void resize(size_type n); | 
 | 94 |  void resize(size_type n, const value_type& v); | 
 | 95 |  void shrink_to_fit(); | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 96 |  bool empty() const noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 97 |  | 
 | 98 |  // element access: | 
 | 99 |  reference operator[](size_type i); | 
 | 100 |  const_reference operator[](size_type i) const; | 
 | 101 |  reference at(size_type i); | 
 | 102 |  const_reference at(size_type i) const; | 
 | 103 |  reference front(); | 
 | 104 |  const_reference front() const; | 
 | 105 |  reference back(); | 
 | 106 |  const_reference back() const; | 
 | 107 |  | 
 | 108 |  // modifiers: | 
 | 109 |  void push_front(const value_type& v); | 
 | 110 |  void push_front(value_type&& v); | 
 | 111 |  void push_back(const value_type& v); | 
 | 112 |  void push_back(value_type&& v); | 
 | 113 |  template <class... Args> void emplace_front(Args&&... args); | 
 | 114 |  template <class... Args> void emplace_back(Args&&... args); | 
 | 115 |  template <class... Args> iterator emplace(const_iterator p, Args&&... args); | 
 | 116 |  iterator insert(const_iterator p, const value_type& v); | 
 | 117 |  iterator insert(const_iterator p, value_type&& v); | 
 | 118 |  iterator insert(const_iterator p, size_type n, const value_type& v); | 
 | 119 |  template <class InputIterator> | 
| Marshall Clow | 3150c35 | 2015-01-22 18:33:29 | [diff] [blame] | 120 |  iterator insert(const_iterator p, InputIterator f, InputIterator l); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 121 |  iterator insert(const_iterator p, initializer_list<value_type> il); | 
 | 122 |  void pop_front(); | 
 | 123 |  void pop_back(); | 
 | 124 |  iterator erase(const_iterator p); | 
 | 125 |  iterator erase(const_iterator f, const_iterator l); | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 126 |  void swap(deque& c) | 
 | 127 |  noexcept(!allocator_type::propagate_on_container_swap::value || | 
 | 128 |  __is_nothrow_swappable<allocator_type>::value); | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 129 |  void clear() noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 130 | }; | 
 | 131 |  | 
 | 132 | template <class T, class Allocator> | 
 | 133 |  bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 
 | 134 | template <class T, class Allocator> | 
 | 135 |  bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 
 | 136 | template <class T, class Allocator> | 
 | 137 |  bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 
 | 138 | template <class T, class Allocator> | 
 | 139 |  bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 
 | 140 | template <class T, class Allocator> | 
 | 141 |  bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 
 | 142 | template <class T, class Allocator> | 
 | 143 |  bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 
 | 144 |  | 
 | 145 | // specialized algorithms: | 
 | 146 | template <class T, class Allocator> | 
| Howard Hinnant | c560727 | 2011-06-03 17:30:28 | [diff] [blame] | 147 |  void swap(deque<T,Allocator>& x, deque<T,Allocator>& y) | 
 | 148 |  noexcept(noexcept(x.swap(y))); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 149 |  | 
 | 150 | } // std | 
 | 151 |  | 
 | 152 | */ | 
 | 153 |  | 
| Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 | [diff] [blame] | 154 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 155 | #pragma GCC system_header | 
| Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 | [diff] [blame] | 156 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 157 |  | 
 | 158 | #include <__config> | 
 | 159 | #include <__split_buffer> | 
 | 160 | #include <type_traits> | 
 | 161 | #include <initializer_list> | 
 | 162 | #include <iterator> | 
 | 163 | #include <algorithm> | 
 | 164 | #include <stdexcept> | 
 | 165 |  | 
| Howard Hinnant | 66c6f97 | 2011-11-29 16:45:27 | [diff] [blame] | 166 | #include <__undef_min_max> | 
 | 167 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 168 | _LIBCPP_BEGIN_NAMESPACE_STD | 
 | 169 |  | 
 | 170 | template <class _Tp, class _Allocator> class __deque_base; | 
| Marshall Clow | ceead9c | 2015-02-18 17:24:08 | [diff] [blame] | 171 | template <class _Tp, class _Allocator = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY deque; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 172 |  | 
 | 173 | template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, | 
 | 174 |  class _DiffType, _DiffType _BlockSize> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 | [diff] [blame] | 175 | class _LIBCPP_TYPE_VIS_ONLY __deque_iterator; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 176 |  | 
 | 177 | template <class _RAIter, | 
 | 178 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 179 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 180 | copy(_RAIter __f, | 
 | 181 |  _RAIter __l, | 
 | 182 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
 | 183 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); | 
 | 184 |  | 
 | 185 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 186 |  class _OutputIterator> | 
 | 187 | _OutputIterator | 
 | 188 | copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 189 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 190 |  _OutputIterator __r); | 
 | 191 |  | 
 | 192 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 193 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 194 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 195 | copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 196 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 197 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
 | 198 |  | 
 | 199 | template <class _RAIter, | 
 | 200 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 201 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 202 | copy_backward(_RAIter __f, | 
 | 203 |  _RAIter __l, | 
 | 204 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
 | 205 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); | 
 | 206 |  | 
 | 207 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 208 |  class _OutputIterator> | 
 | 209 | _OutputIterator | 
 | 210 | copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 211 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 212 |  _OutputIterator __r); | 
 | 213 |  | 
 | 214 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 215 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 216 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 217 | copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 218 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 219 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
 | 220 |  | 
 | 221 | template <class _RAIter, | 
 | 222 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 223 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 224 | move(_RAIter __f, | 
 | 225 |  _RAIter __l, | 
 | 226 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
 | 227 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); | 
 | 228 |  | 
 | 229 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 230 |  class _OutputIterator> | 
 | 231 | _OutputIterator | 
 | 232 | move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 233 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 234 |  _OutputIterator __r); | 
 | 235 |  | 
 | 236 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 237 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 238 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 239 | move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 240 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 241 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
 | 242 |  | 
 | 243 | template <class _RAIter, | 
 | 244 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 245 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 246 | move_backward(_RAIter __f, | 
 | 247 |  _RAIter __l, | 
 | 248 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
 | 249 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); | 
 | 250 |  | 
 | 251 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 252 |  class _OutputIterator> | 
 | 253 | _OutputIterator | 
 | 254 | move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 255 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 256 |  _OutputIterator __r); | 
 | 257 |  | 
 | 258 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 259 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 260 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 261 | move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 262 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 263 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
 | 264 |  | 
 | 265 | template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, | 
 | 266 |  class _DiffType, _DiffType _BlockSize> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 | [diff] [blame] | 267 | class _LIBCPP_TYPE_VIS_ONLY __deque_iterator | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 268 | { | 
 | 269 |  typedef _MapPointer __map_iterator; | 
 | 270 | public: | 
 | 271 |  typedef _Pointer pointer; | 
 | 272 |  typedef _DiffType difference_type; | 
 | 273 | private: | 
 | 274 |  __map_iterator __m_iter_; | 
 | 275 |  pointer __ptr_; | 
 | 276 |  | 
 | 277 |  static const difference_type __block_size = _BlockSize; | 
 | 278 | public: | 
 | 279 |  typedef _ValueType value_type; | 
 | 280 |  typedef random_access_iterator_tag iterator_category; | 
 | 281 |  typedef _Reference reference; | 
 | 282 |  | 
| Marshall Clow | 5a11f94 | 2013-08-06 16:14:36 | [diff] [blame] | 283 |  _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT | 
 | 284 | #if _LIBCPP_STD_VER > 11 | 
 | 285 |  : __m_iter_(nullptr), __ptr_(nullptr) | 
 | 286 | #endif | 
 | 287 |  {} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 288 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 | [diff] [blame] | 289 |  template <class _Pp, class _Rp, class _MP> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 290 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 | [diff] [blame] | 291 |  __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, __block_size>& __it, | 
 | 292 |  typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 293 |  : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {} | 
 | 294 |  | 
 | 295 |  _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;} | 
 | 296 |  _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;} | 
 | 297 |  | 
 | 298 |  _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++() | 
 | 299 |  { | 
 | 300 |  if (++__ptr_ - *__m_iter_ == __block_size) | 
 | 301 |  { | 
 | 302 |  ++__m_iter_; | 
 | 303 |  __ptr_ = *__m_iter_; | 
 | 304 |  } | 
 | 305 |  return *this; | 
 | 306 |  } | 
 | 307 |  | 
 | 308 |  _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int) | 
 | 309 |  { | 
 | 310 |  __deque_iterator __tmp = *this; | 
 | 311 |  ++(*this); | 
 | 312 |  return __tmp; | 
 | 313 |  } | 
 | 314 |  | 
 | 315 |  _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--() | 
 | 316 |  { | 
 | 317 |  if (__ptr_ == *__m_iter_) | 
 | 318 |  { | 
 | 319 |  --__m_iter_; | 
 | 320 |  __ptr_ = *__m_iter_ + __block_size; | 
 | 321 |  } | 
 | 322 |  --__ptr_; | 
 | 323 |  return *this; | 
 | 324 |  } | 
 | 325 |  | 
 | 326 |  _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int) | 
 | 327 |  { | 
 | 328 |  __deque_iterator __tmp = *this; | 
 | 329 |  --(*this); | 
 | 330 |  return __tmp; | 
 | 331 |  } | 
 | 332 |  | 
 | 333 |  _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n) | 
 | 334 |  { | 
 | 335 |  if (__n != 0) | 
 | 336 |  { | 
 | 337 |  __n += __ptr_ - *__m_iter_; | 
 | 338 |  if (__n > 0) | 
 | 339 |  { | 
 | 340 |  __m_iter_ += __n / __block_size; | 
 | 341 |  __ptr_ = *__m_iter_ + __n % __block_size; | 
 | 342 |  } | 
 | 343 |  else // (__n < 0) | 
 | 344 |  { | 
 | 345 |  difference_type __z = __block_size - 1 - __n; | 
 | 346 |  __m_iter_ -= __z / __block_size; | 
 | 347 |  __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size); | 
 | 348 |  } | 
 | 349 |  } | 
 | 350 |  return *this; | 
 | 351 |  } | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 352 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 353 |  _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n) | 
 | 354 |  { | 
 | 355 |  return *this += -__n; | 
 | 356 |  } | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 357 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 358 |  _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const | 
 | 359 |  { | 
 | 360 |  __deque_iterator __t(*this); | 
 | 361 |  __t += __n; | 
 | 362 |  return __t; | 
 | 363 |  } | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 364 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 365 |  _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const | 
 | 366 |  { | 
 | 367 |  __deque_iterator __t(*this); | 
 | 368 |  __t -= __n; | 
 | 369 |  return __t; | 
 | 370 |  } | 
 | 371 |  | 
 | 372 |  _LIBCPP_INLINE_VISIBILITY | 
 | 373 |  friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it) | 
 | 374 |  {return __it + __n;} | 
 | 375 |  | 
 | 376 |  _LIBCPP_INLINE_VISIBILITY | 
 | 377 |  friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y) | 
 | 378 |  { | 
 | 379 |  if (__x != __y) | 
 | 380 |  return (__x.__m_iter_ - __y.__m_iter_) * __block_size | 
 | 381 |  + (__x.__ptr_ - *__x.__m_iter_) | 
 | 382 |  - (__y.__ptr_ - *__y.__m_iter_); | 
 | 383 |  return 0; | 
 | 384 |  } | 
 | 385 |  | 
 | 386 |  _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const | 
 | 387 |  {return *(*this + __n);} | 
 | 388 |  | 
 | 389 |  _LIBCPP_INLINE_VISIBILITY friend | 
 | 390 |  bool operator==(const __deque_iterator& __x, const __deque_iterator& __y) | 
 | 391 |  {return __x.__ptr_ == __y.__ptr_;} | 
 | 392 |  | 
 | 393 |  _LIBCPP_INLINE_VISIBILITY friend | 
 | 394 |  bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) | 
 | 395 |  {return !(__x == __y);} | 
 | 396 |  | 
 | 397 |  _LIBCPP_INLINE_VISIBILITY friend | 
 | 398 |  bool operator<(const __deque_iterator& __x, const __deque_iterator& __y) | 
 | 399 |  {return __x.__m_iter_ < __y.__m_iter_ || | 
 | 400 |  (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);} | 
 | 401 |  | 
 | 402 |  _LIBCPP_INLINE_VISIBILITY friend | 
 | 403 |  bool operator>(const __deque_iterator& __x, const __deque_iterator& __y) | 
 | 404 |  {return __y < __x;} | 
 | 405 |  | 
 | 406 |  _LIBCPP_INLINE_VISIBILITY friend | 
 | 407 |  bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y) | 
 | 408 |  {return !(__y < __x);} | 
 | 409 |  | 
 | 410 |  _LIBCPP_INLINE_VISIBILITY friend | 
 | 411 |  bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) | 
 | 412 |  {return !(__x < __y);} | 
 | 413 |  | 
 | 414 | private: | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 415 |  _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 416 |  : __m_iter_(__m), __ptr_(__p) {} | 
 | 417 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 | [diff] [blame] | 418 |  template <class _Tp, class _Ap> friend class __deque_base; | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 | [diff] [blame] | 419 |  template <class _Tp, class _Ap> friend class _LIBCPP_TYPE_VIS_ONLY deque; | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 | [diff] [blame] | 420 |  template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 | [diff] [blame] | 421 |  friend class _LIBCPP_TYPE_VIS_ONLY __deque_iterator; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 422 |  | 
 | 423 |  template <class _RAIter, | 
 | 424 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 425 |  friend | 
 | 426 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 427 |  copy(_RAIter __f, | 
 | 428 |  _RAIter __l, | 
 | 429 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
 | 430 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); | 
 | 431 |  | 
 | 432 |  template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 433 |  class _OutputIterator> | 
 | 434 |  friend | 
 | 435 |  _OutputIterator | 
 | 436 |  copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 437 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 438 |  _OutputIterator __r); | 
 | 439 |  | 
 | 440 |  template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 441 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 442 |  friend | 
 | 443 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 444 |  copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 445 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 446 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
 | 447 |  | 
 | 448 |  template <class _RAIter, | 
 | 449 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 450 |  friend | 
 | 451 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 452 |  copy_backward(_RAIter __f, | 
 | 453 |  _RAIter __l, | 
 | 454 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
 | 455 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); | 
 | 456 |  | 
 | 457 |  template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 458 |  class _OutputIterator> | 
 | 459 |  friend | 
 | 460 |  _OutputIterator | 
 | 461 |  copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 462 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 463 |  _OutputIterator __r); | 
 | 464 |  | 
 | 465 |  template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 466 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 467 |  friend | 
 | 468 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 469 |  copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 470 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 471 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
 | 472 |  | 
 | 473 |  template <class _RAIter, | 
 | 474 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 475 |  friend | 
 | 476 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 477 |  move(_RAIter __f, | 
 | 478 |  _RAIter __l, | 
 | 479 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
 | 480 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); | 
 | 481 |  | 
 | 482 |  template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 483 |  class _OutputIterator> | 
 | 484 |  friend | 
 | 485 |  _OutputIterator | 
 | 486 |  move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 487 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 488 |  _OutputIterator __r); | 
 | 489 |  | 
 | 490 |  template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 491 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 492 |  friend | 
 | 493 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 494 |  move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 495 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 496 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
 | 497 |  | 
 | 498 |  template <class _RAIter, | 
 | 499 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 500 |  friend | 
 | 501 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 502 |  move_backward(_RAIter __f, | 
 | 503 |  _RAIter __l, | 
 | 504 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
 | 505 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*); | 
 | 506 |  | 
 | 507 |  template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 508 |  class _OutputIterator> | 
 | 509 |  friend | 
 | 510 |  _OutputIterator | 
 | 511 |  move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 512 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 513 |  _OutputIterator __r); | 
 | 514 |  | 
 | 515 |  template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 516 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 517 |  friend | 
 | 518 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 519 |  move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 520 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 521 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 
 | 522 | }; | 
 | 523 |  | 
 | 524 | // copy | 
 | 525 |  | 
 | 526 | template <class _RAIter, | 
 | 527 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 528 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 529 | copy(_RAIter __f, | 
 | 530 |  _RAIter __l, | 
 | 531 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
 | 532 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) | 
 | 533 | { | 
 | 534 |  typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; | 
 | 535 |  typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; | 
 | 536 |  while (__f != __l) | 
 | 537 |  { | 
 | 538 |  pointer __rb = __r.__ptr_; | 
 | 539 |  pointer __re = *__r.__m_iter_ + _B2; | 
 | 540 |  difference_type __bs = __re - __rb; | 
 | 541 |  difference_type __n = __l - __f; | 
 | 542 |  _RAIter __m = __l; | 
 | 543 |  if (__n > __bs) | 
 | 544 |  { | 
 | 545 |  __n = __bs; | 
 | 546 |  __m = __f + __n; | 
 | 547 |  } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 548 |  _VSTD::copy(__f, __m, __rb); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 549 |  __f = __m; | 
 | 550 |  __r += __n; | 
 | 551 |  } | 
 | 552 |  return __r; | 
 | 553 | } | 
 | 554 |  | 
 | 555 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 556 |  class _OutputIterator> | 
 | 557 | _OutputIterator | 
 | 558 | copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 559 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 560 |  _OutputIterator __r) | 
 | 561 | { | 
 | 562 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
 | 563 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
 | 564 |  difference_type __n = __l - __f; | 
 | 565 |  while (__n > 0) | 
 | 566 |  { | 
 | 567 |  pointer __fb = __f.__ptr_; | 
 | 568 |  pointer __fe = *__f.__m_iter_ + _B1; | 
 | 569 |  difference_type __bs = __fe - __fb; | 
 | 570 |  if (__bs > __n) | 
 | 571 |  { | 
 | 572 |  __bs = __n; | 
 | 573 |  __fe = __fb + __bs; | 
 | 574 |  } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 575 |  __r = _VSTD::copy(__fb, __fe, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 576 |  __n -= __bs; | 
 | 577 |  __f += __bs; | 
 | 578 |  } | 
 | 579 |  return __r; | 
 | 580 | } | 
 | 581 |  | 
 | 582 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 583 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 584 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 585 | copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 586 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 587 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) | 
 | 588 | { | 
 | 589 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
 | 590 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
 | 591 |  difference_type __n = __l - __f; | 
 | 592 |  while (__n > 0) | 
 | 593 |  { | 
 | 594 |  pointer __fb = __f.__ptr_; | 
 | 595 |  pointer __fe = *__f.__m_iter_ + _B1; | 
 | 596 |  difference_type __bs = __fe - __fb; | 
 | 597 |  if (__bs > __n) | 
 | 598 |  { | 
 | 599 |  __bs = __n; | 
 | 600 |  __fe = __fb + __bs; | 
 | 601 |  } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 602 |  __r = _VSTD::copy(__fb, __fe, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 603 |  __n -= __bs; | 
 | 604 |  __f += __bs; | 
 | 605 |  } | 
 | 606 |  return __r; | 
 | 607 | } | 
 | 608 |  | 
 | 609 | // copy_backward | 
 | 610 |  | 
 | 611 | template <class _RAIter, | 
 | 612 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 613 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 614 | copy_backward(_RAIter __f, | 
 | 615 |  _RAIter __l, | 
 | 616 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
 | 617 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) | 
 | 618 | { | 
 | 619 |  typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; | 
 | 620 |  typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; | 
 | 621 |  while (__f != __l) | 
 | 622 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 623 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 624 |  pointer __rb = *__rp.__m_iter_; | 
 | 625 |  pointer __re = __rp.__ptr_ + 1; | 
 | 626 |  difference_type __bs = __re - __rb; | 
 | 627 |  difference_type __n = __l - __f; | 
 | 628 |  _RAIter __m = __f; | 
 | 629 |  if (__n > __bs) | 
 | 630 |  { | 
 | 631 |  __n = __bs; | 
 | 632 |  __m = __l - __n; | 
 | 633 |  } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 634 |  _VSTD::copy_backward(__m, __l, __re); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 635 |  __l = __m; | 
 | 636 |  __r -= __n; | 
 | 637 |  } | 
 | 638 |  return __r; | 
 | 639 | } | 
 | 640 |  | 
 | 641 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 642 |  class _OutputIterator> | 
 | 643 | _OutputIterator | 
 | 644 | copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 645 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 646 |  _OutputIterator __r) | 
 | 647 | { | 
 | 648 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
 | 649 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
 | 650 |  difference_type __n = __l - __f; | 
 | 651 |  while (__n > 0) | 
 | 652 |  { | 
 | 653 |  --__l; | 
 | 654 |  pointer __lb = *__l.__m_iter_; | 
 | 655 |  pointer __le = __l.__ptr_ + 1; | 
 | 656 |  difference_type __bs = __le - __lb; | 
 | 657 |  if (__bs > __n) | 
 | 658 |  { | 
 | 659 |  __bs = __n; | 
 | 660 |  __lb = __le - __bs; | 
 | 661 |  } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 662 |  __r = _VSTD::copy_backward(__lb, __le, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 663 |  __n -= __bs; | 
 | 664 |  __l -= __bs - 1; | 
 | 665 |  } | 
 | 666 |  return __r; | 
 | 667 | } | 
 | 668 |  | 
 | 669 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 670 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 671 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 672 | copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 673 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 674 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) | 
 | 675 | { | 
 | 676 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
 | 677 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
 | 678 |  difference_type __n = __l - __f; | 
 | 679 |  while (__n > 0) | 
 | 680 |  { | 
 | 681 |  --__l; | 
 | 682 |  pointer __lb = *__l.__m_iter_; | 
 | 683 |  pointer __le = __l.__ptr_ + 1; | 
 | 684 |  difference_type __bs = __le - __lb; | 
 | 685 |  if (__bs > __n) | 
 | 686 |  { | 
 | 687 |  __bs = __n; | 
 | 688 |  __lb = __le - __bs; | 
 | 689 |  } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 690 |  __r = _VSTD::copy_backward(__lb, __le, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 691 |  __n -= __bs; | 
 | 692 |  __l -= __bs - 1; | 
 | 693 |  } | 
 | 694 |  return __r; | 
 | 695 | } | 
 | 696 |  | 
 | 697 | // move | 
 | 698 |  | 
 | 699 | template <class _RAIter, | 
 | 700 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 701 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 702 | move(_RAIter __f, | 
 | 703 |  _RAIter __l, | 
 | 704 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
 | 705 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) | 
 | 706 | { | 
 | 707 |  typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; | 
 | 708 |  typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; | 
 | 709 |  while (__f != __l) | 
 | 710 |  { | 
 | 711 |  pointer __rb = __r.__ptr_; | 
 | 712 |  pointer __re = *__r.__m_iter_ + _B2; | 
 | 713 |  difference_type __bs = __re - __rb; | 
 | 714 |  difference_type __n = __l - __f; | 
 | 715 |  _RAIter __m = __l; | 
 | 716 |  if (__n > __bs) | 
 | 717 |  { | 
 | 718 |  __n = __bs; | 
 | 719 |  __m = __f + __n; | 
 | 720 |  } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 721 |  _VSTD::move(__f, __m, __rb); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 722 |  __f = __m; | 
 | 723 |  __r += __n; | 
 | 724 |  } | 
 | 725 |  return __r; | 
 | 726 | } | 
 | 727 |  | 
 | 728 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 729 |  class _OutputIterator> | 
 | 730 | _OutputIterator | 
 | 731 | move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 732 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 733 |  _OutputIterator __r) | 
 | 734 | { | 
 | 735 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
 | 736 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
 | 737 |  difference_type __n = __l - __f; | 
 | 738 |  while (__n > 0) | 
 | 739 |  { | 
 | 740 |  pointer __fb = __f.__ptr_; | 
 | 741 |  pointer __fe = *__f.__m_iter_ + _B1; | 
 | 742 |  difference_type __bs = __fe - __fb; | 
 | 743 |  if (__bs > __n) | 
 | 744 |  { | 
 | 745 |  __bs = __n; | 
 | 746 |  __fe = __fb + __bs; | 
 | 747 |  } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 748 |  __r = _VSTD::move(__fb, __fe, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 749 |  __n -= __bs; | 
 | 750 |  __f += __bs; | 
 | 751 |  } | 
 | 752 |  return __r; | 
 | 753 | } | 
 | 754 |  | 
 | 755 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 756 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 757 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 758 | move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 759 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 760 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) | 
 | 761 | { | 
 | 762 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
 | 763 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
 | 764 |  difference_type __n = __l - __f; | 
 | 765 |  while (__n > 0) | 
 | 766 |  { | 
 | 767 |  pointer __fb = __f.__ptr_; | 
 | 768 |  pointer __fe = *__f.__m_iter_ + _B1; | 
 | 769 |  difference_type __bs = __fe - __fb; | 
 | 770 |  if (__bs > __n) | 
 | 771 |  { | 
 | 772 |  __bs = __n; | 
 | 773 |  __fe = __fb + __bs; | 
 | 774 |  } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 775 |  __r = _VSTD::move(__fb, __fe, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 776 |  __n -= __bs; | 
 | 777 |  __f += __bs; | 
 | 778 |  } | 
 | 779 |  return __r; | 
 | 780 | } | 
 | 781 |  | 
 | 782 | // move_backward | 
 | 783 |  | 
 | 784 | template <class _RAIter, | 
 | 785 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 786 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 787 | move_backward(_RAIter __f, | 
 | 788 |  _RAIter __l, | 
 | 789 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 
 | 790 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) | 
 | 791 | { | 
 | 792 |  typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; | 
 | 793 |  typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; | 
 | 794 |  while (__f != __l) | 
 | 795 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 796 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 797 |  pointer __rb = *__rp.__m_iter_; | 
 | 798 |  pointer __re = __rp.__ptr_ + 1; | 
 | 799 |  difference_type __bs = __re - __rb; | 
 | 800 |  difference_type __n = __l - __f; | 
 | 801 |  _RAIter __m = __f; | 
 | 802 |  if (__n > __bs) | 
 | 803 |  { | 
 | 804 |  __n = __bs; | 
 | 805 |  __m = __l - __n; | 
 | 806 |  } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 807 |  _VSTD::move_backward(__m, __l, __re); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 808 |  __l = __m; | 
 | 809 |  __r -= __n; | 
 | 810 |  } | 
 | 811 |  return __r; | 
 | 812 | } | 
 | 813 |  | 
 | 814 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 815 |  class _OutputIterator> | 
 | 816 | _OutputIterator | 
 | 817 | move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 818 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 819 |  _OutputIterator __r) | 
 | 820 | { | 
 | 821 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
 | 822 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
 | 823 |  difference_type __n = __l - __f; | 
 | 824 |  while (__n > 0) | 
 | 825 |  { | 
 | 826 |  --__l; | 
 | 827 |  pointer __lb = *__l.__m_iter_; | 
 | 828 |  pointer __le = __l.__ptr_ + 1; | 
 | 829 |  difference_type __bs = __le - __lb; | 
 | 830 |  if (__bs > __n) | 
 | 831 |  { | 
 | 832 |  __bs = __n; | 
 | 833 |  __lb = __le - __bs; | 
 | 834 |  } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 835 |  __r = _VSTD::move_backward(__lb, __le, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 836 |  __n -= __bs; | 
 | 837 |  __l -= __bs - 1; | 
 | 838 |  } | 
 | 839 |  return __r; | 
 | 840 | } | 
 | 841 |  | 
 | 842 | template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 
 | 843 |  class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 
 | 844 | __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 
 | 845 | move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 
 | 846 |  __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 
 | 847 |  __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) | 
 | 848 | { | 
 | 849 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 
 | 850 |  typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; | 
 | 851 |  difference_type __n = __l - __f; | 
 | 852 |  while (__n > 0) | 
 | 853 |  { | 
 | 854 |  --__l; | 
 | 855 |  pointer __lb = *__l.__m_iter_; | 
 | 856 |  pointer __le = __l.__ptr_ + 1; | 
 | 857 |  difference_type __bs = __le - __lb; | 
 | 858 |  if (__bs > __n) | 
 | 859 |  { | 
 | 860 |  __bs = __n; | 
 | 861 |  __lb = __le - __bs; | 
 | 862 |  } | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 863 |  __r = _VSTD::move_backward(__lb, __le, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 864 |  __n -= __bs; | 
 | 865 |  __l -= __bs - 1; | 
 | 866 |  } | 
 | 867 |  return __r; | 
 | 868 | } | 
 | 869 |  | 
 | 870 | template <bool> | 
 | 871 | class __deque_base_common | 
 | 872 | { | 
 | 873 | protected: | 
 | 874 |  void __throw_length_error() const; | 
 | 875 |  void __throw_out_of_range() const; | 
 | 876 | }; | 
 | 877 |  | 
 | 878 | template <bool __b> | 
 | 879 | void | 
 | 880 | __deque_base_common<__b>::__throw_length_error() const | 
 | 881 | { | 
 | 882 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 883 |  throw length_error("deque"); | 
 | 884 | #endif | 
 | 885 | } | 
 | 886 |  | 
 | 887 | template <bool __b> | 
 | 888 | void | 
 | 889 | __deque_base_common<__b>::__throw_out_of_range() const | 
 | 890 | { | 
 | 891 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 892 |  throw out_of_range("deque"); | 
 | 893 | #endif | 
 | 894 | } | 
 | 895 |  | 
 | 896 | template <class _Tp, class _Allocator> | 
 | 897 | class __deque_base | 
 | 898 |  : protected __deque_base_common<true> | 
 | 899 | { | 
 | 900 |  __deque_base(const __deque_base& __c); | 
 | 901 |  __deque_base& operator=(const __deque_base& __c); | 
 | 902 | protected: | 
 | 903 |  typedef _Tp value_type; | 
 | 904 |  typedef _Allocator allocator_type; | 
 | 905 |  typedef allocator_traits<allocator_type> __alloc_traits; | 
 | 906 |  typedef value_type& reference; | 
 | 907 |  typedef const value_type& const_reference; | 
 | 908 |  typedef typename __alloc_traits::size_type size_type; | 
 | 909 |  typedef typename __alloc_traits::difference_type difference_type; | 
 | 910 |  typedef typename __alloc_traits::pointer pointer; | 
 | 911 |  typedef typename __alloc_traits::const_pointer const_pointer; | 
 | 912 |  | 
 | 913 |  static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16; | 
 | 914 |  | 
 | 915 |  typedef typename __alloc_traits::template | 
 | 916 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES | 
 | 917 |  rebind_alloc<pointer> | 
 | 918 | #else | 
 | 919 |  rebind_alloc<pointer>::other | 
 | 920 | #endif | 
 | 921 |  __pointer_allocator; | 
 | 922 |  typedef allocator_traits<__pointer_allocator> __map_traits; | 
 | 923 |  typedef typename __map_traits::pointer __map_pointer; | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 924 |  typedef typename __alloc_traits::template | 
 | 925 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES | 
 | 926 |  rebind_alloc<const_pointer> | 
 | 927 | #else | 
 | 928 |  rebind_alloc<const_pointer>::other | 
 | 929 | #endif | 
 | 930 |  __const_pointer_allocator; | 
 | 931 |  typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 932 |  typedef __split_buffer<pointer, __pointer_allocator> __map; | 
 | 933 |  | 
 | 934 |  typedef __deque_iterator<value_type, pointer, reference, __map_pointer, | 
 | 935 |  difference_type, __block_size> iterator; | 
 | 936 |  typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer, | 
 | 937 |  difference_type, __block_size> const_iterator; | 
 | 938 |  | 
 | 939 |  __map __map_; | 
 | 940 |  size_type __start_; | 
 | 941 |  __compressed_pair<size_type, allocator_type> __size_; | 
 | 942 |  | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 943 |  iterator begin() _NOEXCEPT; | 
 | 944 |  const_iterator begin() const _NOEXCEPT; | 
 | 945 |  iterator end() _NOEXCEPT; | 
 | 946 |  const_iterator end() const _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 947 |  | 
 | 948 |  _LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();} | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 949 |  _LIBCPP_INLINE_VISIBILITY | 
 | 950 |  const size_type& size() const _NOEXCEPT {return __size_.first();} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 951 |  _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();} | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 952 |  _LIBCPP_INLINE_VISIBILITY | 
 | 953 |  const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 954 |  | 
| Howard Hinnant | 009b2c4 | 2011-06-03 15:16:49 | [diff] [blame] | 955 |  __deque_base() | 
 | 956 |  _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 957 |  explicit __deque_base(const allocator_type& __a); | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 958 | public: | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 959 |  ~__deque_base(); | 
 | 960 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 961 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 962 |  | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 963 |  __deque_base(__deque_base&& __c) | 
 | 964 |  _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 965 |  __deque_base(__deque_base&& __c, const allocator_type& __a); | 
 | 966 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 967 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 968 |  void swap(__deque_base& __c) | 
| Howard Hinnant | b965fed | 2011-06-03 16:20:53 | [diff] [blame] | 969 |  _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 970 |  __is_nothrow_swappable<allocator_type>::value); | 
 | 971 | protected: | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 972 |  void clear() _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 973 |  | 
 | 974 |  bool __invariants() const; | 
 | 975 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 976 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 977 |  void __move_assign(__deque_base& __c) | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 978 |  _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && | 
 | 979 |  is_nothrow_move_assignable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 980 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 981 |  __map_ = _VSTD::move(__c.__map_); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 982 |  __start_ = __c.__start_; | 
 | 983 |  size() = __c.size(); | 
 | 984 |  __move_assign_alloc(__c); | 
 | 985 |  __c.__start_ = __c.size() = 0; | 
 | 986 |  } | 
 | 987 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 988 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 989 |  void __move_assign_alloc(__deque_base& __c) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 990 |  _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value || | 
 | 991 |  is_nothrow_move_assignable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 992 |  {__move_assign_alloc(__c, integral_constant<bool, | 
 | 993 |  __alloc_traits::propagate_on_container_move_assignment::value>());} | 
 | 994 |  | 
 | 995 | private: | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 996 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9cbee43 | 2011-09-02 20:42:31 | [diff] [blame] | 997 |  void __move_assign_alloc(__deque_base& __c, true_type) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 998 |  _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 999 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1000 |  __alloc() = _VSTD::move(__c.__alloc()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1001 |  } | 
 | 1002 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1003 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ec3773c | 2011-12-01 20:21:04 | [diff] [blame] | 1004 |  void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1005 |  {} | 
 | 1006 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1007 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1008 |  static void __swap_alloc(allocator_type& __x, allocator_type& __y) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1009 |  _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || | 
 | 1010 |  __is_nothrow_swappable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1011 |  {__swap_alloc(__x, __y, integral_constant<bool, | 
 | 1012 |  __alloc_traits::propagate_on_container_swap::value>());} | 
 | 1013 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1014 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1015 |  static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1016 |  _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1017 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1018 |  using _VSTD::swap; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1019 |  swap(__x, __y); | 
 | 1020 |  } | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1021 |  | 
 | 1022 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ec3773c | 2011-12-01 20:21:04 | [diff] [blame] | 1023 |  static void __swap_alloc(allocator_type&, allocator_type&, false_type) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1024 |  _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1025 |  {} | 
 | 1026 | }; | 
 | 1027 |  | 
 | 1028 | template <class _Tp, class _Allocator> | 
 | 1029 | bool | 
 | 1030 | __deque_base<_Tp, _Allocator>::__invariants() const | 
 | 1031 | { | 
 | 1032 |  if (!__map_.__invariants()) | 
 | 1033 |  return false; | 
 | 1034 |  if (__map_.size() >= size_type(-1) / __block_size) | 
 | 1035 |  return false; | 
 | 1036 |  for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end(); | 
 | 1037 |  __i != __e; ++__i) | 
 | 1038 |  if (*__i == nullptr) | 
 | 1039 |  return false; | 
 | 1040 |  if (__map_.size() != 0) | 
 | 1041 |  { | 
 | 1042 |  if (size() >= __map_.size() * __block_size) | 
 | 1043 |  return false; | 
 | 1044 |  if (__start_ >= __map_.size() * __block_size - size()) | 
 | 1045 |  return false; | 
 | 1046 |  } | 
 | 1047 |  else | 
 | 1048 |  { | 
 | 1049 |  if (size() != 0) | 
 | 1050 |  return false; | 
 | 1051 |  if (__start_ != 0) | 
 | 1052 |  return false; | 
 | 1053 |  } | 
 | 1054 |  return true; | 
 | 1055 | } | 
 | 1056 |  | 
 | 1057 | template <class _Tp, class _Allocator> | 
 | 1058 | typename __deque_base<_Tp, _Allocator>::iterator | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1059 | __deque_base<_Tp, _Allocator>::begin() _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1060 | { | 
 | 1061 |  __map_pointer __mp = __map_.begin() + __start_ / __block_size; | 
 | 1062 |  return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); | 
 | 1063 | } | 
 | 1064 |  | 
 | 1065 | template <class _Tp, class _Allocator> | 
 | 1066 | typename __deque_base<_Tp, _Allocator>::const_iterator | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1067 | __deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1068 | { | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 1069 |  __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1070 |  return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); | 
 | 1071 | } | 
 | 1072 |  | 
 | 1073 | template <class _Tp, class _Allocator> | 
 | 1074 | typename __deque_base<_Tp, _Allocator>::iterator | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1075 | __deque_base<_Tp, _Allocator>::end() _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1076 | { | 
 | 1077 |  size_type __p = size() + __start_; | 
 | 1078 |  __map_pointer __mp = __map_.begin() + __p / __block_size; | 
 | 1079 |  return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); | 
 | 1080 | } | 
 | 1081 |  | 
 | 1082 | template <class _Tp, class _Allocator> | 
 | 1083 | typename __deque_base<_Tp, _Allocator>::const_iterator | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1084 | __deque_base<_Tp, _Allocator>::end() const _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1085 | { | 
 | 1086 |  size_type __p = size() + __start_; | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 1087 |  __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1088 |  return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); | 
 | 1089 | } | 
 | 1090 |  | 
 | 1091 | template <class _Tp, class _Allocator> | 
 | 1092 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1093 | __deque_base<_Tp, _Allocator>::__deque_base() | 
| Howard Hinnant | 009b2c4 | 2011-06-03 15:16:49 | [diff] [blame] | 1094 |  _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1095 |  : __start_(0), __size_(0) {} | 
 | 1096 |  | 
 | 1097 | template <class _Tp, class _Allocator> | 
 | 1098 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1099 | __deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a) | 
 | 1100 |  : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {} | 
 | 1101 |  | 
 | 1102 | template <class _Tp, class _Allocator> | 
 | 1103 | __deque_base<_Tp, _Allocator>::~__deque_base() | 
 | 1104 | { | 
 | 1105 |  clear(); | 
 | 1106 |  typename __map::iterator __i = __map_.begin(); | 
 | 1107 |  typename __map::iterator __e = __map_.end(); | 
 | 1108 |  for (; __i != __e; ++__i) | 
 | 1109 |  __alloc_traits::deallocate(__alloc(), *__i, __block_size); | 
 | 1110 | } | 
 | 1111 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1112 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1113 |  | 
 | 1114 | template <class _Tp, class _Allocator> | 
 | 1115 | __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1116 |  _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1117 |  : __map_(_VSTD::move(__c.__map_)), | 
 | 1118 |  __start_(_VSTD::move(__c.__start_)), | 
 | 1119 |  __size_(_VSTD::move(__c.__size_)) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1120 | { | 
 | 1121 |  __c.__start_ = 0; | 
 | 1122 |  __c.size() = 0; | 
 | 1123 | } | 
 | 1124 |  | 
 | 1125 | template <class _Tp, class _Allocator> | 
 | 1126 | __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1127 |  : __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)), | 
 | 1128 |  __start_(_VSTD::move(__c.__start_)), | 
 | 1129 |  __size_(_VSTD::move(__c.size()), __a) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1130 | { | 
 | 1131 |  if (__a == __c.__alloc()) | 
 | 1132 |  { | 
 | 1133 |  __c.__start_ = 0; | 
 | 1134 |  __c.size() = 0; | 
 | 1135 |  } | 
 | 1136 |  else | 
 | 1137 |  { | 
 | 1138 |  __map_.clear(); | 
 | 1139 |  __start_ = 0; | 
 | 1140 |  size() = 0; | 
 | 1141 |  } | 
 | 1142 | } | 
 | 1143 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1144 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1145 |  | 
 | 1146 | template <class _Tp, class _Allocator> | 
 | 1147 | void | 
 | 1148 | __deque_base<_Tp, _Allocator>::swap(__deque_base& __c) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1149 |  _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| | 
 | 1150 |  __is_nothrow_swappable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1151 | { | 
 | 1152 |  __map_.swap(__c.__map_); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1153 |  _VSTD::swap(__start_, __c.__start_); | 
 | 1154 |  _VSTD::swap(size(), __c.size()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1155 |  __swap_alloc(__alloc(), __c.__alloc()); | 
 | 1156 | } | 
 | 1157 |  | 
 | 1158 | template <class _Tp, class _Allocator> | 
 | 1159 | void | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1160 | __deque_base<_Tp, _Allocator>::clear() _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1161 | { | 
 | 1162 |  allocator_type& __a = __alloc(); | 
 | 1163 |  for (iterator __i = begin(), __e = end(); __i != __e; ++__i) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1164 |  __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1165 |  size() = 0; | 
 | 1166 |  while (__map_.size() > 2) | 
 | 1167 |  { | 
 | 1168 |  __alloc_traits::deallocate(__a, __map_.front(), __block_size); | 
 | 1169 |  __map_.pop_front(); | 
 | 1170 |  } | 
 | 1171 |  switch (__map_.size()) | 
 | 1172 |  { | 
 | 1173 |  case 1: | 
 | 1174 |  __start_ = __block_size / 2; | 
 | 1175 |  break; | 
 | 1176 |  case 2: | 
 | 1177 |  __start_ = __block_size; | 
 | 1178 |  break; | 
 | 1179 |  } | 
 | 1180 | } | 
 | 1181 |  | 
| Marshall Clow | ceead9c | 2015-02-18 17:24:08 | [diff] [blame] | 1182 | template <class _Tp, class _Allocator /*= allocator<_Tp>*/> | 
| Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 | [diff] [blame] | 1183 | class _LIBCPP_TYPE_VIS_ONLY deque | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1184 |  : private __deque_base<_Tp, _Allocator> | 
 | 1185 | { | 
 | 1186 | public: | 
 | 1187 |  // types: | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 1188 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1189 |  typedef _Tp value_type; | 
 | 1190 |  typedef _Allocator allocator_type; | 
 | 1191 |  | 
 | 1192 |  typedef __deque_base<value_type, allocator_type> __base; | 
 | 1193 |  | 
 | 1194 |  typedef typename __base::__alloc_traits __alloc_traits; | 
 | 1195 |  typedef typename __base::reference reference; | 
 | 1196 |  typedef typename __base::const_reference const_reference; | 
 | 1197 |  typedef typename __base::iterator iterator; | 
 | 1198 |  typedef typename __base::const_iterator const_iterator; | 
 | 1199 |  typedef typename __base::size_type size_type; | 
 | 1200 |  typedef typename __base::difference_type difference_type; | 
 | 1201 |  | 
 | 1202 |  typedef typename __base::pointer pointer; | 
 | 1203 |  typedef typename __base::const_pointer const_pointer; | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1204 |  typedef _VSTD::reverse_iterator<iterator> reverse_iterator; | 
 | 1205 |  typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1206 |  | 
 | 1207 |  // construct/copy/destroy: | 
| Howard Hinnant | 009b2c4 | 2011-06-03 15:16:49 | [diff] [blame] | 1208 |  _LIBCPP_INLINE_VISIBILITY | 
 | 1209 |  deque() | 
 | 1210 |  _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) | 
 | 1211 |  {} | 
| Marshall Clow | 48c7470 | 2014-03-05 19:06:20 | [diff] [blame] | 1212 |  _LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1213 |  explicit deque(size_type __n); | 
| Marshall Clow | ab04aad | 2013-09-07 16:16:19 | [diff] [blame] | 1214 | #if _LIBCPP_STD_VER > 11 | 
 | 1215 |  explicit deque(size_type __n, const _Allocator& __a); | 
 | 1216 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1217 |  deque(size_type __n, const value_type& __v); | 
 | 1218 |  deque(size_type __n, const value_type& __v, const allocator_type& __a); | 
 | 1219 |  template <class _InputIter> | 
 | 1220 |  deque(_InputIter __f, _InputIter __l, | 
 | 1221 |  typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); | 
 | 1222 |  template <class _InputIter> | 
 | 1223 |  deque(_InputIter __f, _InputIter __l, const allocator_type& __a, | 
 | 1224 |  typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0); | 
 | 1225 |  deque(const deque& __c); | 
 | 1226 |  deque(const deque& __c, const allocator_type& __a); | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1227 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1228 |  deque(initializer_list<value_type> __il); | 
 | 1229 |  deque(initializer_list<value_type> __il, const allocator_type& __a); | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1230 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1231 |  | 
 | 1232 |  deque& operator=(const deque& __c); | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1233 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1234 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1235 |  deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;} | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1236 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1237 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1238 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1239 |  deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1240 |  deque(deque&& __c, const allocator_type& __a); | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1241 |  deque& operator=(deque&& __c) | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 1242 |  _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && | 
 | 1243 |  is_nothrow_move_assignable<allocator_type>::value); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1244 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1245 |  | 
 | 1246 |  template <class _InputIter> | 
 | 1247 |  void assign(_InputIter __f, _InputIter __l, | 
 | 1248 |  typename enable_if<__is_input_iterator<_InputIter>::value && | 
 | 1249 |  !__is_random_access_iterator<_InputIter>::value>::type* = 0); | 
 | 1250 |  template <class _RAIter> | 
 | 1251 |  void assign(_RAIter __f, _RAIter __l, | 
 | 1252 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0); | 
 | 1253 |  void assign(size_type __n, const value_type& __v); | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1254 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1255 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1256 |  void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1257 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1258 |  | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1259 |  allocator_type get_allocator() const _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1260 |  | 
 | 1261 |  // iterators: | 
 | 1262 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1263 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1264 |  iterator begin() _NOEXCEPT {return __base::begin();} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1265 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1266 |  const_iterator begin() const _NOEXCEPT {return __base::begin();} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1267 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1268 |  iterator end() _NOEXCEPT {return __base::end();} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1269 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1270 |  const_iterator end() const _NOEXCEPT {return __base::end();} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1271 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1272 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1273 |  reverse_iterator rbegin() _NOEXCEPT | 
 | 1274 |  {return reverse_iterator(__base::end());} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1275 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1276 |  const_reverse_iterator rbegin() const _NOEXCEPT | 
 | 1277 |  {return const_reverse_iterator(__base::end());} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1278 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1279 |  reverse_iterator rend() _NOEXCEPT | 
 | 1280 |  {return reverse_iterator(__base::begin());} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1281 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1282 |  const_reverse_iterator rend() const _NOEXCEPT | 
 | 1283 |  {return const_reverse_iterator(__base::begin());} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1284 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1285 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1286 |  const_iterator cbegin() const _NOEXCEPT | 
 | 1287 |  {return __base::begin();} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1288 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1289 |  const_iterator cend() const _NOEXCEPT | 
 | 1290 |  {return __base::end();} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1291 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1292 |  const_reverse_iterator crbegin() const _NOEXCEPT | 
 | 1293 |  {return const_reverse_iterator(__base::end());} | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1294 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1295 |  const_reverse_iterator crend() const _NOEXCEPT | 
 | 1296 |  {return const_reverse_iterator(__base::begin());} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1297 |  | 
 | 1298 |  // capacity: | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1299 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1300 |  size_type size() const _NOEXCEPT {return __base::size();} | 
 | 1301 |  _LIBCPP_INLINE_VISIBILITY | 
 | 1302 |  size_type max_size() const _NOEXCEPT | 
 | 1303 |  {return __alloc_traits::max_size(__base::__alloc());} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1304 |  void resize(size_type __n); | 
 | 1305 |  void resize(size_type __n, const value_type& __v); | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 1306 |  void shrink_to_fit() _NOEXCEPT; | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1307 |  _LIBCPP_INLINE_VISIBILITY | 
 | 1308 |  bool empty() const _NOEXCEPT {return __base::size() == 0;} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1309 |  | 
 | 1310 |  // element access: | 
 | 1311 |  reference operator[](size_type __i); | 
 | 1312 |  const_reference operator[](size_type __i) const; | 
 | 1313 |  reference at(size_type __i); | 
 | 1314 |  const_reference at(size_type __i) const; | 
 | 1315 |  reference front(); | 
 | 1316 |  const_reference front() const; | 
 | 1317 |  reference back(); | 
 | 1318 |  const_reference back() const; | 
 | 1319 |  | 
 | 1320 |  // 23.2.2.3 modifiers: | 
 | 1321 |  void push_front(const value_type& __v); | 
 | 1322 |  void push_back(const value_type& __v); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1323 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
 | 1324 | #ifndef _LIBCPP_HAS_NO_VARIADICS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1325 |  template <class... _Args> void emplace_front(_Args&&... __args); | 
 | 1326 |  template <class... _Args> void emplace_back(_Args&&... __args); | 
 | 1327 |  template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1328 | #endif // _LIBCPP_HAS_NO_VARIADICS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1329 |  void push_front(value_type&& __v); | 
 | 1330 |  void push_back(value_type&& __v); | 
 | 1331 |  iterator insert(const_iterator __p, value_type&& __v); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1332 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1333 |  iterator insert(const_iterator __p, const value_type& __v); | 
 | 1334 |  iterator insert(const_iterator __p, size_type __n, const value_type& __v); | 
 | 1335 |  template <class _InputIter> | 
| Marshall Clow | 3150c35 | 2015-01-22 18:33:29 | [diff] [blame] | 1336 |  iterator insert(const_iterator __p, _InputIter __f, _InputIter __l, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1337 |  typename enable_if<__is_input_iterator<_InputIter>::value | 
| Marshall Clow | 3150c35 | 2015-01-22 18:33:29 | [diff] [blame] | 1338 |  &&!__is_forward_iterator<_InputIter>::value>::type* = 0); | 
 | 1339 |  template <class _ForwardIterator> | 
 | 1340 |  iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, | 
 | 1341 |  typename enable_if<__is_forward_iterator<_ForwardIterator>::value | 
 | 1342 |  &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type* = 0); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1343 |  template <class _BiIter> | 
| Marshall Clow | 3150c35 | 2015-01-22 18:33:29 | [diff] [blame] | 1344 |  iterator insert(const_iterator __p, _BiIter __f, _BiIter __l, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1345 |  typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0); | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1346 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1347 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1348 |  iterator insert(const_iterator __p, initializer_list<value_type> __il) | 
 | 1349 |  {return insert(__p, __il.begin(), __il.end());} | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1350 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1351 |  void pop_front(); | 
 | 1352 |  void pop_back(); | 
 | 1353 |  iterator erase(const_iterator __p); | 
 | 1354 |  iterator erase(const_iterator __f, const_iterator __l); | 
 | 1355 |  | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1356 |  void swap(deque& __c) | 
 | 1357 |  _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || | 
 | 1358 |  __is_nothrow_swappable<allocator_type>::value); | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1359 |  void clear() _NOEXCEPT; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1360 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1361 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1362 |  bool __invariants() const {return __base::__invariants();} | 
 | 1363 | private: | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 1364 |  typedef typename __base::__map_const_pointer __map_const_pointer; | 
 | 1365 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1366 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1367 |  static size_type __recommend_blocks(size_type __n) | 
 | 1368 |  { | 
 | 1369 |  return __n / __base::__block_size + (__n % __base::__block_size != 0); | 
 | 1370 |  } | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1371 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1372 |  size_type __capacity() const | 
 | 1373 |  { | 
 | 1374 |  return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1; | 
 | 1375 |  } | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1376 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1377 |  size_type __front_spare() const | 
 | 1378 |  { | 
 | 1379 |  return __base::__start_; | 
 | 1380 |  } | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1381 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1382 |  size_type __back_spare() const | 
 | 1383 |  { | 
 | 1384 |  return __capacity() - (__base::__start_ + __base::size()); | 
 | 1385 |  } | 
 | 1386 |  | 
 | 1387 |  template <class _InpIter> | 
 | 1388 |  void __append(_InpIter __f, _InpIter __l, | 
 | 1389 |  typename enable_if<__is_input_iterator<_InpIter>::value && | 
 | 1390 |  !__is_forward_iterator<_InpIter>::value>::type* = 0); | 
 | 1391 |  template <class _ForIter> | 
 | 1392 |  void __append(_ForIter __f, _ForIter __l, | 
 | 1393 |  typename enable_if<__is_forward_iterator<_ForIter>::value>::type* = 0); | 
 | 1394 |  void __append(size_type __n); | 
 | 1395 |  void __append(size_type __n, const value_type& __v); | 
 | 1396 |  void __erase_to_end(const_iterator __f); | 
 | 1397 |  void __add_front_capacity(); | 
 | 1398 |  void __add_front_capacity(size_type __n); | 
 | 1399 |  void __add_back_capacity(); | 
 | 1400 |  void __add_back_capacity(size_type __n); | 
 | 1401 |  iterator __move_and_check(iterator __f, iterator __l, iterator __r, | 
 | 1402 |  const_pointer& __vt); | 
 | 1403 |  iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r, | 
 | 1404 |  const_pointer& __vt); | 
 | 1405 |  void __move_construct_and_check(iterator __f, iterator __l, | 
 | 1406 |  iterator __r, const_pointer& __vt); | 
 | 1407 |  void __move_construct_backward_and_check(iterator __f, iterator __l, | 
 | 1408 |  iterator __r, const_pointer& __vt); | 
 | 1409 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1410 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1411 |  void __copy_assign_alloc(const deque& __c) | 
 | 1412 |  {__copy_assign_alloc(__c, integral_constant<bool, | 
 | 1413 |  __alloc_traits::propagate_on_container_copy_assignment::value>());} | 
 | 1414 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1415 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1416 |  void __copy_assign_alloc(const deque& __c, true_type) | 
 | 1417 |  { | 
 | 1418 |  if (__base::__alloc() != __c.__alloc()) | 
 | 1419 |  { | 
 | 1420 |  clear(); | 
 | 1421 |  shrink_to_fit(); | 
 | 1422 |  } | 
 | 1423 |  __base::__alloc() = __c.__alloc(); | 
 | 1424 |  __base::__map_.__alloc() = __c.__map_.__alloc(); | 
 | 1425 |  } | 
 | 1426 |  | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1427 |  _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | ec3773c | 2011-12-01 20:21:04 | [diff] [blame] | 1428 |  void __copy_assign_alloc(const deque&, false_type) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1429 |  {} | 
 | 1430 |  | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 1431 |  void __move_assign(deque& __c, true_type) | 
 | 1432 |  _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1433 |  void __move_assign(deque& __c, false_type); | 
 | 1434 | }; | 
 | 1435 |  | 
 | 1436 | template <class _Tp, class _Allocator> | 
 | 1437 | deque<_Tp, _Allocator>::deque(size_type __n) | 
 | 1438 | { | 
 | 1439 |  if (__n > 0) | 
 | 1440 |  __append(__n); | 
 | 1441 | } | 
 | 1442 |  | 
| Marshall Clow | ab04aad | 2013-09-07 16:16:19 | [diff] [blame] | 1443 | #if _LIBCPP_STD_VER > 11 | 
 | 1444 | template <class _Tp, class _Allocator> | 
 | 1445 | deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a) | 
 | 1446 |  : __base(__a) | 
 | 1447 | { | 
 | 1448 |  if (__n > 0) | 
 | 1449 |  __append(__n); | 
 | 1450 | } | 
 | 1451 | #endif | 
 | 1452 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1453 | template <class _Tp, class _Allocator> | 
 | 1454 | deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) | 
 | 1455 | { | 
 | 1456 |  if (__n > 0) | 
 | 1457 |  __append(__n, __v); | 
 | 1458 | } | 
 | 1459 |  | 
 | 1460 | template <class _Tp, class _Allocator> | 
 | 1461 | deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a) | 
 | 1462 |  : __base(__a) | 
 | 1463 | { | 
 | 1464 |  if (__n > 0) | 
 | 1465 |  __append(__n, __v); | 
 | 1466 | } | 
 | 1467 |  | 
 | 1468 | template <class _Tp, class _Allocator> | 
 | 1469 | template <class _InputIter> | 
 | 1470 | deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, | 
 | 1471 |  typename enable_if<__is_input_iterator<_InputIter>::value>::type*) | 
 | 1472 | { | 
 | 1473 |  __append(__f, __l); | 
 | 1474 | } | 
 | 1475 |  | 
 | 1476 | template <class _Tp, class _Allocator> | 
 | 1477 | template <class _InputIter> | 
 | 1478 | deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a, | 
 | 1479 |  typename enable_if<__is_input_iterator<_InputIter>::value>::type*) | 
 | 1480 |  : __base(__a) | 
 | 1481 | { | 
 | 1482 |  __append(__f, __l); | 
 | 1483 | } | 
 | 1484 |  | 
 | 1485 | template <class _Tp, class _Allocator> | 
 | 1486 | deque<_Tp, _Allocator>::deque(const deque& __c) | 
 | 1487 |  : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc())) | 
 | 1488 | { | 
 | 1489 |  __append(__c.begin(), __c.end()); | 
 | 1490 | } | 
 | 1491 |  | 
 | 1492 | template <class _Tp, class _Allocator> | 
 | 1493 | deque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a) | 
 | 1494 |  : __base(__a) | 
 | 1495 | { | 
 | 1496 |  __append(__c.begin(), __c.end()); | 
 | 1497 | } | 
 | 1498 |  | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1499 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
 | 1500 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1501 | template <class _Tp, class _Allocator> | 
 | 1502 | deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il) | 
 | 1503 | { | 
 | 1504 |  __append(__il.begin(), __il.end()); | 
 | 1505 | } | 
 | 1506 |  | 
 | 1507 | template <class _Tp, class _Allocator> | 
 | 1508 | deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a) | 
 | 1509 |  : __base(__a) | 
 | 1510 | { | 
 | 1511 |  __append(__il.begin(), __il.end()); | 
 | 1512 | } | 
 | 1513 |  | 
| Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 | [diff] [blame] | 1514 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS | 
 | 1515 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1516 | template <class _Tp, class _Allocator> | 
 | 1517 | deque<_Tp, _Allocator>& | 
 | 1518 | deque<_Tp, _Allocator>::operator=(const deque& __c) | 
 | 1519 | { | 
 | 1520 |  if (this != &__c) | 
 | 1521 |  { | 
 | 1522 |  __copy_assign_alloc(__c); | 
 | 1523 |  assign(__c.begin(), __c.end()); | 
 | 1524 |  } | 
 | 1525 |  return *this; | 
 | 1526 | } | 
 | 1527 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1528 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1529 |  | 
 | 1530 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1531 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1532 | deque<_Tp, _Allocator>::deque(deque&& __c) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 1533 |  _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1534 |  : __base(_VSTD::move(__c)) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1535 | { | 
 | 1536 | } | 
 | 1537 |  | 
 | 1538 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1539 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1540 | deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1541 |  : __base(_VSTD::move(__c), __a) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1542 | { | 
 | 1543 |  if (__a != __c.__alloc()) | 
 | 1544 |  { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 | [diff] [blame] | 1545 |  typedef move_iterator<iterator> _Ip; | 
 | 1546 |  assign(_Ip(__c.begin()), _Ip(__c.end())); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1547 |  } | 
 | 1548 | } | 
 | 1549 |  | 
 | 1550 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1551 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1552 | deque<_Tp, _Allocator>& | 
 | 1553 | deque<_Tp, _Allocator>::operator=(deque&& __c) | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 1554 |  _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && | 
 | 1555 |  is_nothrow_move_assignable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1556 | { | 
 | 1557 |  __move_assign(__c, integral_constant<bool, | 
 | 1558 |  __alloc_traits::propagate_on_container_move_assignment::value>()); | 
 | 1559 |  return *this; | 
 | 1560 | } | 
 | 1561 |  | 
 | 1562 | template <class _Tp, class _Allocator> | 
 | 1563 | void | 
 | 1564 | deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type) | 
 | 1565 | { | 
 | 1566 |  if (__base::__alloc() != __c.__alloc()) | 
 | 1567 |  { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 | [diff] [blame] | 1568 |  typedef move_iterator<iterator> _Ip; | 
 | 1569 |  assign(_Ip(__c.begin()), _Ip(__c.end())); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1570 |  } | 
 | 1571 |  else | 
 | 1572 |  __move_assign(__c, true_type()); | 
 | 1573 | } | 
 | 1574 |  | 
 | 1575 | template <class _Tp, class _Allocator> | 
 | 1576 | void | 
 | 1577 | deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type) | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 1578 |  _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1579 | { | 
 | 1580 |  clear(); | 
 | 1581 |  shrink_to_fit(); | 
 | 1582 |  __base::__move_assign(__c); | 
 | 1583 | } | 
 | 1584 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1585 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1586 |  | 
 | 1587 | template <class _Tp, class _Allocator> | 
 | 1588 | template <class _InputIter> | 
 | 1589 | void | 
 | 1590 | deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l, | 
 | 1591 |  typename enable_if<__is_input_iterator<_InputIter>::value && | 
 | 1592 |  !__is_random_access_iterator<_InputIter>::value>::type*) | 
 | 1593 | { | 
 | 1594 |  iterator __i = __base::begin(); | 
 | 1595 |  iterator __e = __base::end(); | 
| Eric Fiselier | b991975 | 2014-10-27 19:28:20 | [diff] [blame] | 1596 |  for (; __f != __l && __i != __e; ++__f, (void) ++__i) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1597 |  *__i = *__f; | 
 | 1598 |  if (__f != __l) | 
 | 1599 |  __append(__f, __l); | 
 | 1600 |  else | 
 | 1601 |  __erase_to_end(__i); | 
 | 1602 | } | 
 | 1603 |  | 
 | 1604 | template <class _Tp, class _Allocator> | 
 | 1605 | template <class _RAIter> | 
 | 1606 | void | 
 | 1607 | deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l, | 
 | 1608 |  typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*) | 
 | 1609 | { | 
 | 1610 |  if (static_cast<size_type>(__l - __f) > __base::size()) | 
 | 1611 |  { | 
 | 1612 |  _RAIter __m = __f + __base::size(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1613 |  _VSTD::copy(__f, __m, __base::begin()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1614 |  __append(__m, __l); | 
 | 1615 |  } | 
 | 1616 |  else | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1617 |  __erase_to_end(_VSTD::copy(__f, __l, __base::begin())); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1618 | } | 
 | 1619 |  | 
 | 1620 | template <class _Tp, class _Allocator> | 
 | 1621 | void | 
 | 1622 | deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v) | 
 | 1623 | { | 
 | 1624 |  if (__n > __base::size()) | 
 | 1625 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1626 |  _VSTD::fill_n(__base::begin(), __base::size(), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1627 |  __n -= __base::size(); | 
 | 1628 |  __append(__n, __v); | 
 | 1629 |  } | 
 | 1630 |  else | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1631 |  __erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1632 | } | 
 | 1633 |  | 
 | 1634 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1635 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1636 | _Allocator | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 1637 | deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1638 | { | 
 | 1639 |  return __base::__alloc(); | 
 | 1640 | } | 
 | 1641 |  | 
 | 1642 | template <class _Tp, class _Allocator> | 
 | 1643 | void | 
 | 1644 | deque<_Tp, _Allocator>::resize(size_type __n) | 
 | 1645 | { | 
 | 1646 |  if (__n > __base::size()) | 
 | 1647 |  __append(__n - __base::size()); | 
 | 1648 |  else if (__n < __base::size()) | 
 | 1649 |  __erase_to_end(__base::begin() + __n); | 
 | 1650 | } | 
 | 1651 |  | 
 | 1652 | template <class _Tp, class _Allocator> | 
 | 1653 | void | 
 | 1654 | deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v) | 
 | 1655 | { | 
 | 1656 |  if (__n > __base::size()) | 
 | 1657 |  __append(__n - __base::size(), __v); | 
 | 1658 |  else if (__n < __base::size()) | 
 | 1659 |  __erase_to_end(__base::begin() + __n); | 
 | 1660 | } | 
 | 1661 |  | 
 | 1662 | template <class _Tp, class _Allocator> | 
 | 1663 | void | 
| Howard Hinnant | 18884f4 | 2011-06-02 21:38:57 | [diff] [blame] | 1664 | deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1665 | { | 
 | 1666 |  allocator_type& __a = __base::__alloc(); | 
 | 1667 |  if (empty()) | 
 | 1668 |  { | 
 | 1669 |  while (__base::__map_.size() > 0) | 
 | 1670 |  { | 
 | 1671 |  __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 
 | 1672 |  __base::__map_.pop_back(); | 
 | 1673 |  } | 
 | 1674 |  __base::__start_ = 0; | 
 | 1675 |  } | 
 | 1676 |  else | 
 | 1677 |  { | 
 | 1678 |  if (__front_spare() >= __base::__block_size) | 
 | 1679 |  { | 
 | 1680 |  __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); | 
 | 1681 |  __base::__map_.pop_front(); | 
 | 1682 |  __base::__start_ -= __base::__block_size; | 
 | 1683 |  } | 
 | 1684 |  if (__back_spare() >= __base::__block_size) | 
 | 1685 |  { | 
 | 1686 |  __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 
 | 1687 |  __base::__map_.pop_back(); | 
 | 1688 |  } | 
 | 1689 |  } | 
 | 1690 |  __base::__map_.shrink_to_fit(); | 
 | 1691 | } | 
 | 1692 |  | 
 | 1693 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1694 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1695 | typename deque<_Tp, _Allocator>::reference | 
 | 1696 | deque<_Tp, _Allocator>::operator[](size_type __i) | 
 | 1697 | { | 
 | 1698 |  size_type __p = __base::__start_ + __i; | 
 | 1699 |  return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 
 | 1700 | } | 
 | 1701 |  | 
 | 1702 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1703 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1704 | typename deque<_Tp, _Allocator>::const_reference | 
 | 1705 | deque<_Tp, _Allocator>::operator[](size_type __i) const | 
 | 1706 | { | 
 | 1707 |  size_type __p = __base::__start_ + __i; | 
 | 1708 |  return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 
 | 1709 | } | 
 | 1710 |  | 
 | 1711 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1712 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1713 | typename deque<_Tp, _Allocator>::reference | 
 | 1714 | deque<_Tp, _Allocator>::at(size_type __i) | 
 | 1715 | { | 
 | 1716 |  if (__i >= __base::size()) | 
 | 1717 |  __base::__throw_out_of_range(); | 
 | 1718 |  size_type __p = __base::__start_ + __i; | 
 | 1719 |  return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 
 | 1720 | } | 
 | 1721 |  | 
 | 1722 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1723 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1724 | typename deque<_Tp, _Allocator>::const_reference | 
 | 1725 | deque<_Tp, _Allocator>::at(size_type __i) const | 
 | 1726 | { | 
 | 1727 |  if (__i >= __base::size()) | 
 | 1728 |  __base::__throw_out_of_range(); | 
 | 1729 |  size_type __p = __base::__start_ + __i; | 
 | 1730 |  return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 
 | 1731 | } | 
 | 1732 |  | 
 | 1733 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1734 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1735 | typename deque<_Tp, _Allocator>::reference | 
 | 1736 | deque<_Tp, _Allocator>::front() | 
 | 1737 | { | 
 | 1738 |  return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) | 
 | 1739 |  + __base::__start_ % __base::__block_size); | 
 | 1740 | } | 
 | 1741 |  | 
 | 1742 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1743 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1744 | typename deque<_Tp, _Allocator>::const_reference | 
 | 1745 | deque<_Tp, _Allocator>::front() const | 
 | 1746 | { | 
 | 1747 |  return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) | 
 | 1748 |  + __base::__start_ % __base::__block_size); | 
 | 1749 | } | 
 | 1750 |  | 
 | 1751 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1752 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1753 | typename deque<_Tp, _Allocator>::reference | 
 | 1754 | deque<_Tp, _Allocator>::back() | 
 | 1755 | { | 
 | 1756 |  size_type __p = __base::size() + __base::__start_ - 1; | 
 | 1757 |  return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 
 | 1758 | } | 
 | 1759 |  | 
 | 1760 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 1761 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1762 | typename deque<_Tp, _Allocator>::const_reference | 
 | 1763 | deque<_Tp, _Allocator>::back() const | 
 | 1764 | { | 
 | 1765 |  size_type __p = __base::size() + __base::__start_ - 1; | 
 | 1766 |  return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 
 | 1767 | } | 
 | 1768 |  | 
 | 1769 | template <class _Tp, class _Allocator> | 
 | 1770 | void | 
 | 1771 | deque<_Tp, _Allocator>::push_back(const value_type& __v) | 
 | 1772 | { | 
 | 1773 |  allocator_type& __a = __base::__alloc(); | 
 | 1774 |  if (__back_spare() == 0) | 
 | 1775 |  __add_back_capacity(); | 
 | 1776 |  // __back_spare() >= 1 | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1777 |  __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1778 |  ++__base::size(); | 
 | 1779 | } | 
 | 1780 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1781 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1782 |  | 
 | 1783 | template <class _Tp, class _Allocator> | 
 | 1784 | void | 
 | 1785 | deque<_Tp, _Allocator>::push_back(value_type&& __v) | 
 | 1786 | { | 
 | 1787 |  allocator_type& __a = __base::__alloc(); | 
 | 1788 |  if (__back_spare() == 0) | 
 | 1789 |  __add_back_capacity(); | 
 | 1790 |  // __back_spare() >= 1 | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1791 |  __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1792 |  ++__base::size(); | 
 | 1793 | } | 
 | 1794 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1795 | #ifndef _LIBCPP_HAS_NO_VARIADICS | 
 | 1796 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1797 | template <class _Tp, class _Allocator> | 
 | 1798 | template <class... _Args> | 
 | 1799 | void | 
 | 1800 | deque<_Tp, _Allocator>::emplace_back(_Args&&... __args) | 
 | 1801 | { | 
 | 1802 |  allocator_type& __a = __base::__alloc(); | 
 | 1803 |  if (__back_spare() == 0) | 
 | 1804 |  __add_back_capacity(); | 
 | 1805 |  // __back_spare() >= 1 | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1806 |  __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1807 |  ++__base::size(); | 
 | 1808 | } | 
 | 1809 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1810 | #endif // _LIBCPP_HAS_NO_VARIADICS | 
 | 1811 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1812 |  | 
 | 1813 | template <class _Tp, class _Allocator> | 
 | 1814 | void | 
 | 1815 | deque<_Tp, _Allocator>::push_front(const value_type& __v) | 
 | 1816 | { | 
 | 1817 |  allocator_type& __a = __base::__alloc(); | 
 | 1818 |  if (__front_spare() == 0) | 
 | 1819 |  __add_front_capacity(); | 
 | 1820 |  // __front_spare() >= 1 | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1821 |  __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1822 |  --__base::__start_; | 
 | 1823 |  ++__base::size(); | 
 | 1824 | } | 
 | 1825 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1826 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1827 |  | 
 | 1828 | template <class _Tp, class _Allocator> | 
 | 1829 | void | 
 | 1830 | deque<_Tp, _Allocator>::push_front(value_type&& __v) | 
 | 1831 | { | 
 | 1832 |  allocator_type& __a = __base::__alloc(); | 
 | 1833 |  if (__front_spare() == 0) | 
 | 1834 |  __add_front_capacity(); | 
 | 1835 |  // __front_spare() >= 1 | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1836 |  __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1837 |  --__base::__start_; | 
 | 1838 |  ++__base::size(); | 
 | 1839 | } | 
 | 1840 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1841 | #ifndef _LIBCPP_HAS_NO_VARIADICS | 
 | 1842 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1843 | template <class _Tp, class _Allocator> | 
 | 1844 | template <class... _Args> | 
 | 1845 | void | 
 | 1846 | deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) | 
 | 1847 | { | 
 | 1848 |  allocator_type& __a = __base::__alloc(); | 
 | 1849 |  if (__front_spare() == 0) | 
 | 1850 |  __add_front_capacity(); | 
 | 1851 |  // __front_spare() >= 1 | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1852 |  __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1853 |  --__base::__start_; | 
 | 1854 |  ++__base::size(); | 
 | 1855 | } | 
 | 1856 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1857 | #endif // _LIBCPP_HAS_NO_VARIADICS | 
 | 1858 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1859 |  | 
 | 1860 | template <class _Tp, class _Allocator> | 
 | 1861 | typename deque<_Tp, _Allocator>::iterator | 
 | 1862 | deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) | 
 | 1863 | { | 
 | 1864 |  size_type __pos = __p - __base::begin(); | 
 | 1865 |  size_type __to_end = __base::size() - __pos; | 
 | 1866 |  allocator_type& __a = __base::__alloc(); | 
 | 1867 |  if (__pos < __to_end) | 
 | 1868 |  { // insert by shifting things backward | 
 | 1869 |  if (__front_spare() == 0) | 
 | 1870 |  __add_front_capacity(); | 
 | 1871 |  // __front_spare() >= 1 | 
 | 1872 |  if (__pos == 0) | 
 | 1873 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1874 |  __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1875 |  --__base::__start_; | 
 | 1876 |  ++__base::size(); | 
 | 1877 |  } | 
 | 1878 |  else | 
 | 1879 |  { | 
 | 1880 |  const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); | 
 | 1881 |  iterator __b = __base::begin(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1882 |  iterator __bm1 = _VSTD::prev(__b); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1883 |  if (__vt == pointer_traits<const_pointer>::pointer_to(*__b)) | 
 | 1884 |  __vt = pointer_traits<const_pointer>::pointer_to(*__bm1); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1885 |  __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1886 |  --__base::__start_; | 
 | 1887 |  ++__base::size(); | 
 | 1888 |  if (__pos > 1) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1889 |  __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1890 |  *__b = *__vt; | 
 | 1891 |  } | 
 | 1892 |  } | 
 | 1893 |  else | 
 | 1894 |  { // insert by shifting things forward | 
 | 1895 |  if (__back_spare() == 0) | 
 | 1896 |  __add_back_capacity(); | 
 | 1897 |  // __back_capacity >= 1 | 
 | 1898 |  size_type __de = __base::size() - __pos; | 
 | 1899 |  if (__de == 0) | 
 | 1900 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1901 |  __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1902 |  ++__base::size(); | 
 | 1903 |  } | 
 | 1904 |  else | 
 | 1905 |  { | 
 | 1906 |  const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); | 
 | 1907 |  iterator __e = __base::end(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1908 |  iterator __em1 = _VSTD::prev(__e); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1909 |  if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1)) | 
 | 1910 |  __vt = pointer_traits<const_pointer>::pointer_to(*__e); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1911 |  __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1912 |  ++__base::size(); | 
 | 1913 |  if (__de > 1) | 
 | 1914 |  __e = __move_backward_and_check(__e - __de, __em1, __e, __vt); | 
 | 1915 |  *--__e = *__vt; | 
 | 1916 |  } | 
 | 1917 |  } | 
 | 1918 |  return __base::begin() + __pos; | 
 | 1919 | } | 
 | 1920 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1921 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1922 |  | 
 | 1923 | template <class _Tp, class _Allocator> | 
 | 1924 | typename deque<_Tp, _Allocator>::iterator | 
 | 1925 | deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) | 
 | 1926 | { | 
 | 1927 |  size_type __pos = __p - __base::begin(); | 
 | 1928 |  size_type __to_end = __base::size() - __pos; | 
 | 1929 |  allocator_type& __a = __base::__alloc(); | 
 | 1930 |  if (__pos < __to_end) | 
 | 1931 |  { // insert by shifting things backward | 
 | 1932 |  if (__front_spare() == 0) | 
 | 1933 |  __add_front_capacity(); | 
 | 1934 |  // __front_spare() >= 1 | 
 | 1935 |  if (__pos == 0) | 
 | 1936 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1937 |  __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1938 |  --__base::__start_; | 
 | 1939 |  ++__base::size(); | 
 | 1940 |  } | 
 | 1941 |  else | 
 | 1942 |  { | 
 | 1943 |  iterator __b = __base::begin(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1944 |  iterator __bm1 = _VSTD::prev(__b); | 
 | 1945 |  __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1946 |  --__base::__start_; | 
 | 1947 |  ++__base::size(); | 
 | 1948 |  if (__pos > 1) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1949 |  __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); | 
 | 1950 |  *__b = _VSTD::move(__v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1951 |  } | 
 | 1952 |  } | 
 | 1953 |  else | 
 | 1954 |  { // insert by shifting things forward | 
 | 1955 |  if (__back_spare() == 0) | 
 | 1956 |  __add_back_capacity(); | 
 | 1957 |  // __back_capacity >= 1 | 
 | 1958 |  size_type __de = __base::size() - __pos; | 
 | 1959 |  if (__de == 0) | 
 | 1960 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1961 |  __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1962 |  ++__base::size(); | 
 | 1963 |  } | 
 | 1964 |  else | 
 | 1965 |  { | 
 | 1966 |  iterator __e = __base::end(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1967 |  iterator __em1 = _VSTD::prev(__e); | 
 | 1968 |  __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1969 |  ++__base::size(); | 
 | 1970 |  if (__de > 1) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1971 |  __e = _VSTD::move_backward(__e - __de, __em1, __e); | 
 | 1972 |  *--__e = _VSTD::move(__v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1973 |  } | 
 | 1974 |  } | 
 | 1975 |  return __base::begin() + __pos; | 
 | 1976 | } | 
 | 1977 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 1978 | #ifndef _LIBCPP_HAS_NO_VARIADICS | 
 | 1979 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1980 | template <class _Tp, class _Allocator> | 
 | 1981 | template <class... _Args> | 
 | 1982 | typename deque<_Tp, _Allocator>::iterator | 
 | 1983 | deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) | 
 | 1984 | { | 
 | 1985 |  size_type __pos = __p - __base::begin(); | 
 | 1986 |  size_type __to_end = __base::size() - __pos; | 
 | 1987 |  allocator_type& __a = __base::__alloc(); | 
 | 1988 |  if (__pos < __to_end) | 
 | 1989 |  { // insert by shifting things backward | 
 | 1990 |  if (__front_spare() == 0) | 
 | 1991 |  __add_front_capacity(); | 
 | 1992 |  // __front_spare() >= 1 | 
 | 1993 |  if (__pos == 0) | 
 | 1994 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 1995 |  __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1996 |  --__base::__start_; | 
 | 1997 |  ++__base::size(); | 
 | 1998 |  } | 
 | 1999 |  else | 
 | 2000 |  { | 
| Howard Hinnant | a58402a | 2012-07-08 23:23:04 | [diff] [blame] | 2001 |  value_type __tmp(_VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2002 |  iterator __b = __base::begin(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2003 |  iterator __bm1 = _VSTD::prev(__b); | 
 | 2004 |  __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2005 |  --__base::__start_; | 
 | 2006 |  ++__base::size(); | 
 | 2007 |  if (__pos > 1) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2008 |  __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); | 
| Howard Hinnant | a58402a | 2012-07-08 23:23:04 | [diff] [blame] | 2009 |  *__b = _VSTD::move(__tmp); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2010 |  } | 
 | 2011 |  } | 
 | 2012 |  else | 
 | 2013 |  { // insert by shifting things forward | 
 | 2014 |  if (__back_spare() == 0) | 
 | 2015 |  __add_back_capacity(); | 
 | 2016 |  // __back_capacity >= 1 | 
 | 2017 |  size_type __de = __base::size() - __pos; | 
 | 2018 |  if (__de == 0) | 
 | 2019 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2020 |  __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2021 |  ++__base::size(); | 
 | 2022 |  } | 
 | 2023 |  else | 
 | 2024 |  { | 
| Howard Hinnant | a58402a | 2012-07-08 23:23:04 | [diff] [blame] | 2025 |  value_type __tmp(_VSTD::forward<_Args>(__args)...); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2026 |  iterator __e = __base::end(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2027 |  iterator __em1 = _VSTD::prev(__e); | 
 | 2028 |  __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2029 |  ++__base::size(); | 
 | 2030 |  if (__de > 1) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2031 |  __e = _VSTD::move_backward(__e - __de, __em1, __e); | 
| Howard Hinnant | a58402a | 2012-07-08 23:23:04 | [diff] [blame] | 2032 |  *--__e = _VSTD::move(__tmp); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2033 |  } | 
 | 2034 |  } | 
 | 2035 |  return __base::begin() + __pos; | 
 | 2036 | } | 
 | 2037 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 2038 | #endif // _LIBCPP_HAS_NO_VARIADICS | 
 | 2039 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2040 |  | 
 | 2041 | template <class _Tp, class _Allocator> | 
 | 2042 | typename deque<_Tp, _Allocator>::iterator | 
 | 2043 | deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) | 
 | 2044 | { | 
 | 2045 |  size_type __pos = __p - __base::begin(); | 
 | 2046 |  size_type __to_end = __base::size() - __pos; | 
 | 2047 |  allocator_type& __a = __base::__alloc(); | 
 | 2048 |  if (__pos < __to_end) | 
 | 2049 |  { // insert by shifting things backward | 
 | 2050 |  if (__n > __front_spare()) | 
 | 2051 |  __add_front_capacity(__n - __front_spare()); | 
 | 2052 |  // __n <= __front_spare() | 
 | 2053 |  size_type __old_n = __n; | 
 | 2054 |  iterator __old_begin = __base::begin(); | 
 | 2055 |  iterator __i = __old_begin; | 
 | 2056 |  if (__n > __pos) | 
 | 2057 |  { | 
 | 2058 |  for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2059 |  __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2060 |  __n = __pos; | 
 | 2061 |  } | 
 | 2062 |  if (__n > 0) | 
 | 2063 |  { | 
 | 2064 |  const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); | 
 | 2065 |  iterator __obn = __old_begin + __n; | 
 | 2066 |  __move_construct_backward_and_check(__old_begin, __obn, __i, __vt); | 
 | 2067 |  if (__n < __pos) | 
 | 2068 |  __old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2069 |  _VSTD::fill_n(__old_begin, __n, *__vt); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2070 |  } | 
 | 2071 |  } | 
 | 2072 |  else | 
 | 2073 |  { // insert by shifting things forward | 
 | 2074 |  size_type __back_capacity = __back_spare(); | 
 | 2075 |  if (__n > __back_capacity) | 
 | 2076 |  __add_back_capacity(__n - __back_capacity); | 
 | 2077 |  // __n <= __back_capacity | 
 | 2078 |  size_type __old_n = __n; | 
 | 2079 |  iterator __old_end = __base::end(); | 
 | 2080 |  iterator __i = __old_end; | 
 | 2081 |  size_type __de = __base::size() - __pos; | 
 | 2082 |  if (__n > __de) | 
 | 2083 |  { | 
 | 2084 |  for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2085 |  __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2086 |  __n = __de; | 
 | 2087 |  } | 
 | 2088 |  if (__n > 0) | 
 | 2089 |  { | 
 | 2090 |  const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); | 
 | 2091 |  iterator __oen = __old_end - __n; | 
 | 2092 |  __move_construct_and_check(__oen, __old_end, __i, __vt); | 
 | 2093 |  if (__n < __de) | 
 | 2094 |  __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2095 |  _VSTD::fill_n(__old_end - __n, __n, *__vt); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2096 |  } | 
 | 2097 |  } | 
 | 2098 |  return __base::begin() + __pos; | 
 | 2099 | } | 
 | 2100 |  | 
 | 2101 | template <class _Tp, class _Allocator> | 
 | 2102 | template <class _InputIter> | 
 | 2103 | typename deque<_Tp, _Allocator>::iterator | 
 | 2104 | deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l, | 
 | 2105 |  typename enable_if<__is_input_iterator<_InputIter>::value | 
| Marshall Clow | 3150c35 | 2015-01-22 18:33:29 | [diff] [blame] | 2106 |  &&!__is_forward_iterator<_InputIter>::value>::type*) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2107 | { | 
 | 2108 |  __split_buffer<value_type, allocator_type&> __buf(__base::__alloc()); | 
 | 2109 |  __buf.__construct_at_end(__f, __l); | 
 | 2110 |  typedef typename __split_buffer<value_type, allocator_type&>::iterator __bi; | 
 | 2111 |  return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end())); | 
 | 2112 | } | 
 | 2113 |  | 
 | 2114 | template <class _Tp, class _Allocator> | 
| Marshall Clow | 3150c35 | 2015-01-22 18:33:29 | [diff] [blame] | 2115 | template <class _ForwardIterator> | 
 | 2116 | typename deque<_Tp, _Allocator>::iterator | 
 | 2117 | deque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, | 
 | 2118 |  typename enable_if<__is_forward_iterator<_ForwardIterator>::value | 
 | 2119 |  &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type*) | 
 | 2120 | { | 
 | 2121 |  size_type __n = _VSTD::distance(__f, __l); | 
 | 2122 |  __split_buffer<value_type, allocator_type&> __buf(__n, 0, __base::__alloc()); | 
 | 2123 |  __buf.__construct_at_end(__f, __l); | 
 | 2124 |  typedef typename __split_buffer<value_type, allocator_type&>::iterator __fwd; | 
 | 2125 |  return insert(__p, move_iterator<__fwd>(__buf.begin()), move_iterator<__fwd>(__buf.end())); | 
 | 2126 | } | 
 | 2127 |  | 
 | 2128 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2129 | template <class _BiIter> | 
 | 2130 | typename deque<_Tp, _Allocator>::iterator | 
 | 2131 | deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, | 
 | 2132 |  typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type*) | 
 | 2133 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2134 |  size_type __n = _VSTD::distance(__f, __l); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2135 |  size_type __pos = __p - __base::begin(); | 
 | 2136 |  size_type __to_end = __base::size() - __pos; | 
 | 2137 |  allocator_type& __a = __base::__alloc(); | 
 | 2138 |  if (__pos < __to_end) | 
 | 2139 |  { // insert by shifting things backward | 
 | 2140 |  if (__n > __front_spare()) | 
 | 2141 |  __add_front_capacity(__n - __front_spare()); | 
 | 2142 |  // __n <= __front_spare() | 
 | 2143 |  size_type __old_n = __n; | 
 | 2144 |  iterator __old_begin = __base::begin(); | 
 | 2145 |  iterator __i = __old_begin; | 
 | 2146 |  _BiIter __m = __f; | 
 | 2147 |  if (__n > __pos) | 
 | 2148 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2149 |  __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2150 |  for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2151 |  __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2152 |  __n = __pos; | 
 | 2153 |  } | 
 | 2154 |  if (__n > 0) | 
 | 2155 |  { | 
 | 2156 |  iterator __obn = __old_begin + __n; | 
 | 2157 |  for (iterator __j = __obn; __j != __old_begin;) | 
 | 2158 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2159 |  __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2160 |  --__base::__start_; | 
 | 2161 |  ++__base::size(); | 
 | 2162 |  } | 
 | 2163 |  if (__n < __pos) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2164 |  __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin); | 
 | 2165 |  _VSTD::copy(__m, __l, __old_begin); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2166 |  } | 
 | 2167 |  } | 
 | 2168 |  else | 
 | 2169 |  { // insert by shifting things forward | 
 | 2170 |  size_type __back_capacity = __back_spare(); | 
 | 2171 |  if (__n > __back_capacity) | 
 | 2172 |  __add_back_capacity(__n - __back_capacity); | 
 | 2173 |  // __n <= __back_capacity | 
 | 2174 |  size_type __old_n = __n; | 
 | 2175 |  iterator __old_end = __base::end(); | 
 | 2176 |  iterator __i = __old_end; | 
 | 2177 |  _BiIter __m = __l; | 
 | 2178 |  size_type __de = __base::size() - __pos; | 
 | 2179 |  if (__n > __de) | 
 | 2180 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2181 |  __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de); | 
| Eric Fiselier | b991975 | 2014-10-27 19:28:20 | [diff] [blame] | 2182 |  for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2183 |  __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2184 |  __n = __de; | 
 | 2185 |  } | 
 | 2186 |  if (__n > 0) | 
 | 2187 |  { | 
 | 2188 |  iterator __oen = __old_end - __n; | 
 | 2189 |  for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2190 |  __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2191 |  if (__n < __de) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2192 |  __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end); | 
 | 2193 |  _VSTD::copy_backward(__f, __m, __old_end); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2194 |  } | 
 | 2195 |  } | 
 | 2196 |  return __base::begin() + __pos; | 
 | 2197 | } | 
 | 2198 |  | 
 | 2199 | template <class _Tp, class _Allocator> | 
 | 2200 | template <class _InpIter> | 
 | 2201 | void | 
 | 2202 | deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l, | 
 | 2203 |  typename enable_if<__is_input_iterator<_InpIter>::value && | 
 | 2204 |  !__is_forward_iterator<_InpIter>::value>::type*) | 
 | 2205 | { | 
 | 2206 |  for (; __f != __l; ++__f) | 
 | 2207 |  push_back(*__f); | 
 | 2208 | } | 
 | 2209 |  | 
 | 2210 | template <class _Tp, class _Allocator> | 
 | 2211 | template <class _ForIter> | 
 | 2212 | void | 
 | 2213 | deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l, | 
 | 2214 |  typename enable_if<__is_forward_iterator<_ForIter>::value>::type*) | 
 | 2215 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2216 |  size_type __n = _VSTD::distance(__f, __l); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2217 |  allocator_type& __a = __base::__alloc(); | 
 | 2218 |  size_type __back_capacity = __back_spare(); | 
 | 2219 |  if (__n > __back_capacity) | 
 | 2220 |  __add_back_capacity(__n - __back_capacity); | 
 | 2221 |  // __n <= __back_capacity | 
| Eric Fiselier | b991975 | 2014-10-27 19:28:20 | [diff] [blame] | 2222 |  for (iterator __i = __base::end(); __f != __l; ++__i, (void) ++__f, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2223 |  __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__f); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2224 | } | 
 | 2225 |  | 
 | 2226 | template <class _Tp, class _Allocator> | 
 | 2227 | void | 
 | 2228 | deque<_Tp, _Allocator>::__append(size_type __n) | 
 | 2229 | { | 
 | 2230 |  allocator_type& __a = __base::__alloc(); | 
 | 2231 |  size_type __back_capacity = __back_spare(); | 
 | 2232 |  if (__n > __back_capacity) | 
 | 2233 |  __add_back_capacity(__n - __back_capacity); | 
 | 2234 |  // __n <= __back_capacity | 
 | 2235 |  for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2236 |  __alloc_traits::construct(__a, _VSTD::addressof(*__i)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2237 | } | 
 | 2238 |  | 
 | 2239 | template <class _Tp, class _Allocator> | 
 | 2240 | void | 
 | 2241 | deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v) | 
 | 2242 | { | 
 | 2243 |  allocator_type& __a = __base::__alloc(); | 
 | 2244 |  size_type __back_capacity = __back_spare(); | 
 | 2245 |  if (__n > __back_capacity) | 
 | 2246 |  __add_back_capacity(__n - __back_capacity); | 
 | 2247 |  // __n <= __back_capacity | 
 | 2248 |  for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2249 |  __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2250 | } | 
 | 2251 |  | 
 | 2252 | // Create front capacity for one block of elements. | 
 | 2253 | // Strong guarantee. Either do it or don't touch anything. | 
 | 2254 | template <class _Tp, class _Allocator> | 
 | 2255 | void | 
 | 2256 | deque<_Tp, _Allocator>::__add_front_capacity() | 
 | 2257 | { | 
 | 2258 |  allocator_type& __a = __base::__alloc(); | 
 | 2259 |  if (__back_spare() >= __base::__block_size) | 
 | 2260 |  { | 
 | 2261 |  __base::__start_ += __base::__block_size; | 
 | 2262 |  pointer __pt = __base::__map_.back(); | 
 | 2263 |  __base::__map_.pop_back(); | 
 | 2264 |  __base::__map_.push_front(__pt); | 
 | 2265 |  } | 
 | 2266 |  // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer | 
 | 2267 |  else if (__base::__map_.size() < __base::__map_.capacity()) | 
 | 2268 |  { // we can put the new buffer into the map, but don't shift things around | 
 | 2269 |  // until all buffers are allocated. If we throw, we don't need to fix | 
 | 2270 |  // anything up (any added buffers are undetectible) | 
 | 2271 |  if (__base::__map_.__front_spare() > 0) | 
 | 2272 |  __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); | 
 | 2273 |  else | 
 | 2274 |  { | 
 | 2275 |  __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
 | 2276 |  // Done allocating, reorder capacity | 
 | 2277 |  pointer __pt = __base::__map_.back(); | 
 | 2278 |  __base::__map_.pop_back(); | 
 | 2279 |  __base::__map_.push_front(__pt); | 
 | 2280 |  } | 
 | 2281 |  __base::__start_ = __base::__map_.size() == 1 ? | 
 | 2282 |  __base::__block_size / 2 : | 
 | 2283 |  __base::__start_ + __base::__block_size; | 
 | 2284 |  } | 
 | 2285 |  // Else need to allocate 1 buffer, *and* we need to reallocate __map_. | 
 | 2286 |  else | 
 | 2287 |  { | 
 | 2288 |  __split_buffer<pointer, typename __base::__pointer_allocator&> | 
 | 2289 |  __buf(max<size_type>(2 * __base::__map_.capacity(), 1), | 
 | 2290 |  0, __base::__map_.__alloc()); | 
| Marshall Clow | d07fcd6 | 2015-03-09 17:08:51 | [diff] [blame] | 2291 |  | 
 | 2292 | typedef __allocator_destructor<_Allocator> _Dp; | 
 | 2293 | unique_ptr<pointer, _Dp> __hold( | 
 | 2294 | __alloc_traits::allocate(__a, __base::__block_size), | 
 | 2295 | _Dp(__a, __base::__block_size)); | 
 | 2296 | __buf.push_back(__hold.get()); | 
 | 2297 | __hold.release(); | 
 | 2298 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2299 |  for (typename __base::__map_pointer __i = __base::__map_.begin(); | 
 | 2300 |  __i != __base::__map_.end(); ++__i) | 
 | 2301 |  __buf.push_back(*__i); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2302 |  _VSTD::swap(__base::__map_.__first_, __buf.__first_); | 
 | 2303 |  _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); | 
 | 2304 |  _VSTD::swap(__base::__map_.__end_, __buf.__end_); | 
 | 2305 |  _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2306 |  __base::__start_ = __base::__map_.size() == 1 ? | 
 | 2307 |  __base::__block_size / 2 : | 
 | 2308 |  __base::__start_ + __base::__block_size; | 
 | 2309 |  } | 
 | 2310 | } | 
 | 2311 |  | 
 | 2312 | // Create front capacity for __n elements. | 
 | 2313 | // Strong guarantee. Either do it or don't touch anything. | 
 | 2314 | template <class _Tp, class _Allocator> | 
 | 2315 | void | 
 | 2316 | deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) | 
 | 2317 | { | 
 | 2318 |  allocator_type& __a = __base::__alloc(); | 
 | 2319 |  size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); | 
 | 2320 |  // Number of unused blocks at back: | 
 | 2321 |  size_type __back_capacity = __back_spare() / __base::__block_size; | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2322 |  __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2323 |  __nb -= __back_capacity; // number of blocks need to allocate | 
 | 2324 |  // If __nb == 0, then we have sufficient capacity. | 
 | 2325 |  if (__nb == 0) | 
 | 2326 |  { | 
 | 2327 |  __base::__start_ += __base::__block_size * __back_capacity; | 
 | 2328 |  for (; __back_capacity > 0; --__back_capacity) | 
 | 2329 |  { | 
 | 2330 |  pointer __pt = __base::__map_.back(); | 
 | 2331 |  __base::__map_.pop_back(); | 
 | 2332 |  __base::__map_.push_front(__pt); | 
 | 2333 |  } | 
 | 2334 |  } | 
 | 2335 |  // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers | 
 | 2336 |  else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) | 
 | 2337 |  { // we can put the new buffers into the map, but don't shift things around | 
 | 2338 |  // until all buffers are allocated. If we throw, we don't need to fix | 
 | 2339 |  // anything up (any added buffers are undetectible) | 
 | 2340 |  for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1)) | 
 | 2341 |  { | 
 | 2342 |  if (__base::__map_.__front_spare() == 0) | 
 | 2343 |  break; | 
 | 2344 |  __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); | 
 | 2345 |  } | 
 | 2346 |  for (; __nb > 0; --__nb, ++__back_capacity) | 
 | 2347 |  __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
 | 2348 |  // Done allocating, reorder capacity | 
 | 2349 |  __base::__start_ += __back_capacity * __base::__block_size; | 
 | 2350 |  for (; __back_capacity > 0; --__back_capacity) | 
 | 2351 |  { | 
 | 2352 |  pointer __pt = __base::__map_.back(); | 
 | 2353 |  __base::__map_.pop_back(); | 
 | 2354 |  __base::__map_.push_front(__pt); | 
 | 2355 |  } | 
 | 2356 |  } | 
 | 2357 |  // Else need to allocate __nb buffers, *and* we need to reallocate __map_. | 
 | 2358 |  else | 
 | 2359 |  { | 
 | 2360 |  size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty(); | 
 | 2361 |  __split_buffer<pointer, typename __base::__pointer_allocator&> | 
 | 2362 |  __buf(max<size_type>(2* __base::__map_.capacity(), | 
 | 2363 |  __nb + __base::__map_.size()), | 
 | 2364 |  0, __base::__map_.__alloc()); | 
 | 2365 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 2366 |  try | 
 | 2367 |  { | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 2368 | #endif // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2369 |  for (; __nb > 0; --__nb) | 
 | 2370 |  __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
 | 2371 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 2372 |  } | 
 | 2373 |  catch (...) | 
 | 2374 |  { | 
 | 2375 |  for (typename __base::__map_pointer __i = __buf.begin(); | 
 | 2376 |  __i != __buf.end(); ++__i) | 
 | 2377 |  __alloc_traits::deallocate(__a, *__i, __base::__block_size); | 
 | 2378 |  throw; | 
 | 2379 |  } | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 2380 | #endif // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2381 |  for (; __back_capacity > 0; --__back_capacity) | 
 | 2382 |  { | 
 | 2383 |  __buf.push_back(__base::__map_.back()); | 
 | 2384 |  __base::__map_.pop_back(); | 
 | 2385 |  } | 
 | 2386 |  for (typename __base::__map_pointer __i = __base::__map_.begin(); | 
 | 2387 |  __i != __base::__map_.end(); ++__i) | 
 | 2388 |  __buf.push_back(*__i); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2389 |  _VSTD::swap(__base::__map_.__first_, __buf.__first_); | 
 | 2390 |  _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); | 
 | 2391 |  _VSTD::swap(__base::__map_.__end_, __buf.__end_); | 
 | 2392 |  _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2393 |  __base::__start_ += __ds; | 
 | 2394 |  } | 
 | 2395 | } | 
 | 2396 |  | 
 | 2397 | // Create back capacity for one block of elements. | 
 | 2398 | // Strong guarantee. Either do it or don't touch anything. | 
 | 2399 | template <class _Tp, class _Allocator> | 
 | 2400 | void | 
 | 2401 | deque<_Tp, _Allocator>::__add_back_capacity() | 
 | 2402 | { | 
 | 2403 |  allocator_type& __a = __base::__alloc(); | 
 | 2404 |  if (__front_spare() >= __base::__block_size) | 
 | 2405 |  { | 
 | 2406 |  __base::__start_ -= __base::__block_size; | 
 | 2407 |  pointer __pt = __base::__map_.front(); | 
 | 2408 |  __base::__map_.pop_front(); | 
 | 2409 |  __base::__map_.push_back(__pt); | 
 | 2410 |  } | 
 | 2411 |  // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers | 
 | 2412 |  else if (__base::__map_.size() < __base::__map_.capacity()) | 
 | 2413 |  { // we can put the new buffer into the map, but don't shift things around | 
 | 2414 |  // until it is allocated. If we throw, we don't need to fix | 
 | 2415 |  // anything up (any added buffers are undetectible) | 
 | 2416 |  if (__base::__map_.__back_spare() != 0) | 
 | 2417 |  __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
 | 2418 |  else | 
 | 2419 |  { | 
 | 2420 |  __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); | 
 | 2421 |  // Done allocating, reorder capacity | 
 | 2422 |  pointer __pt = __base::__map_.front(); | 
 | 2423 |  __base::__map_.pop_front(); | 
 | 2424 |  __base::__map_.push_back(__pt); | 
 | 2425 |  } | 
 | 2426 |  } | 
 | 2427 |  // Else need to allocate 1 buffer, *and* we need to reallocate __map_. | 
 | 2428 |  else | 
 | 2429 |  { | 
 | 2430 |  __split_buffer<pointer, typename __base::__pointer_allocator&> | 
 | 2431 |  __buf(max<size_type>(2* __base::__map_.capacity(), 1), | 
 | 2432 |  __base::__map_.size(), | 
 | 2433 |  __base::__map_.__alloc()); | 
| Marshall Clow | d07fcd6 | 2015-03-09 17:08:51 | [diff] [blame] | 2434 |  | 
 | 2435 | typedef __allocator_destructor<_Allocator> _Dp; | 
 | 2436 | unique_ptr<pointer, _Dp> __hold( | 
 | 2437 | __alloc_traits::allocate(__a, __base::__block_size), | 
 | 2438 | _Dp(__a, __base::__block_size)); | 
 | 2439 | __buf.push_back(__hold.get()); | 
 | 2440 | __hold.release(); | 
 | 2441 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2442 |  for (typename __base::__map_pointer __i = __base::__map_.end(); | 
 | 2443 |  __i != __base::__map_.begin();) | 
 | 2444 |  __buf.push_front(*--__i); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2445 |  _VSTD::swap(__base::__map_.__first_, __buf.__first_); | 
 | 2446 |  _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); | 
 | 2447 |  _VSTD::swap(__base::__map_.__end_, __buf.__end_); | 
 | 2448 |  _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2449 |  } | 
 | 2450 | } | 
 | 2451 |  | 
 | 2452 | // Create back capacity for __n elements. | 
 | 2453 | // Strong guarantee. Either do it or don't touch anything. | 
 | 2454 | template <class _Tp, class _Allocator> | 
 | 2455 | void | 
 | 2456 | deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) | 
 | 2457 | { | 
 | 2458 |  allocator_type& __a = __base::__alloc(); | 
 | 2459 |  size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); | 
 | 2460 |  // Number of unused blocks at front: | 
 | 2461 |  size_type __front_capacity = __front_spare() / __base::__block_size; | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2462 |  __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2463 |  __nb -= __front_capacity; // number of blocks need to allocate | 
 | 2464 |  // If __nb == 0, then we have sufficient capacity. | 
 | 2465 |  if (__nb == 0) | 
 | 2466 |  { | 
 | 2467 |  __base::__start_ -= __base::__block_size * __front_capacity; | 
 | 2468 |  for (; __front_capacity > 0; --__front_capacity) | 
 | 2469 |  { | 
 | 2470 |  pointer __pt = __base::__map_.front(); | 
 | 2471 |  __base::__map_.pop_front(); | 
 | 2472 |  __base::__map_.push_back(__pt); | 
 | 2473 |  } | 
 | 2474 |  } | 
 | 2475 |  // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers | 
 | 2476 |  else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) | 
 | 2477 |  { // we can put the new buffers into the map, but don't shift things around | 
 | 2478 |  // until all buffers are allocated. If we throw, we don't need to fix | 
 | 2479 |  // anything up (any added buffers are undetectible) | 
 | 2480 |  for (; __nb > 0; --__nb) | 
 | 2481 |  { | 
 | 2482 |  if (__base::__map_.__back_spare() == 0) | 
 | 2483 |  break; | 
 | 2484 |  __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
 | 2485 |  } | 
 | 2486 |  for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ += | 
 | 2487 |  __base::__block_size - (__base::__map_.size() == 1)) | 
 | 2488 |  __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); | 
 | 2489 |  // Done allocating, reorder capacity | 
 | 2490 |  __base::__start_ -= __base::__block_size * __front_capacity; | 
 | 2491 |  for (; __front_capacity > 0; --__front_capacity) | 
 | 2492 |  { | 
 | 2493 |  pointer __pt = __base::__map_.front(); | 
 | 2494 |  __base::__map_.pop_front(); | 
 | 2495 |  __base::__map_.push_back(__pt); | 
 | 2496 |  } | 
 | 2497 |  } | 
 | 2498 |  // Else need to allocate __nb buffers, *and* we need to reallocate __map_. | 
 | 2499 |  else | 
 | 2500 |  { | 
 | 2501 |  size_type __ds = __front_capacity * __base::__block_size; | 
 | 2502 |  __split_buffer<pointer, typename __base::__pointer_allocator&> | 
 | 2503 |  __buf(max<size_type>(2* __base::__map_.capacity(), | 
 | 2504 |  __nb + __base::__map_.size()), | 
 | 2505 |  __base::__map_.size() - __front_capacity, | 
 | 2506 |  __base::__map_.__alloc()); | 
 | 2507 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 2508 |  try | 
 | 2509 |  { | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 2510 | #endif // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2511 |  for (; __nb > 0; --__nb) | 
 | 2512 |  __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 
 | 2513 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
 | 2514 |  } | 
 | 2515 |  catch (...) | 
 | 2516 |  { | 
 | 2517 |  for (typename __base::__map_pointer __i = __buf.begin(); | 
 | 2518 |  __i != __buf.end(); ++__i) | 
 | 2519 |  __alloc_traits::deallocate(__a, *__i, __base::__block_size); | 
 | 2520 |  throw; | 
 | 2521 |  } | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 | [diff] [blame] | 2522 | #endif // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2523 |  for (; __front_capacity > 0; --__front_capacity) | 
 | 2524 |  { | 
 | 2525 |  __buf.push_back(__base::__map_.front()); | 
 | 2526 |  __base::__map_.pop_front(); | 
 | 2527 |  } | 
 | 2528 |  for (typename __base::__map_pointer __i = __base::__map_.end(); | 
 | 2529 |  __i != __base::__map_.begin();) | 
 | 2530 |  __buf.push_front(*--__i); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2531 |  _VSTD::swap(__base::__map_.__first_, __buf.__first_); | 
 | 2532 |  _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); | 
 | 2533 |  _VSTD::swap(__base::__map_.__end_, __buf.__end_); | 
 | 2534 |  _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2535 |  __base::__start_ -= __ds; | 
 | 2536 |  } | 
 | 2537 | } | 
 | 2538 |  | 
 | 2539 | template <class _Tp, class _Allocator> | 
 | 2540 | void | 
 | 2541 | deque<_Tp, _Allocator>::pop_front() | 
 | 2542 | { | 
 | 2543 |  allocator_type& __a = __base::__alloc(); | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 2544 |  __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() + | 
 | 2545 |  __base::__start_ / __base::__block_size) + | 
 | 2546 |  __base::__start_ % __base::__block_size)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2547 |  --__base::size(); | 
 | 2548 |  if (++__base::__start_ >= 2 * __base::__block_size) | 
 | 2549 |  { | 
 | 2550 |  __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); | 
 | 2551 |  __base::__map_.pop_front(); | 
 | 2552 |  __base::__start_ -= __base::__block_size; | 
 | 2553 |  } | 
 | 2554 | } | 
 | 2555 |  | 
 | 2556 | template <class _Tp, class _Allocator> | 
 | 2557 | void | 
 | 2558 | deque<_Tp, _Allocator>::pop_back() | 
 | 2559 | { | 
 | 2560 |  allocator_type& __a = __base::__alloc(); | 
 | 2561 |  size_type __p = __base::size() + __base::__start_ - 1; | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 2562 |  __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() + | 
 | 2563 |  __p / __base::__block_size) + | 
 | 2564 |  __p % __base::__block_size)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2565 |  --__base::size(); | 
 | 2566 |  if (__back_spare() >= 2 * __base::__block_size) | 
 | 2567 |  { | 
 | 2568 |  __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 
 | 2569 |  __base::__map_.pop_back(); | 
 | 2570 |  } | 
 | 2571 | } | 
 | 2572 |  | 
 | 2573 | // move assign [__f, __l) to [__r, __r + (__l-__f)). | 
 | 2574 | // If __vt points into [__f, __l), then subtract (__f - __r) from __vt. | 
 | 2575 | template <class _Tp, class _Allocator> | 
 | 2576 | typename deque<_Tp, _Allocator>::iterator | 
 | 2577 | deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r, | 
 | 2578 |  const_pointer& __vt) | 
 | 2579 | { | 
 | 2580 |  // as if | 
 | 2581 |  // for (; __f != __l; ++__f, ++__r) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2582 |  // *__r = _VSTD::move(*__f); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2583 |  difference_type __n = __l - __f; | 
 | 2584 |  while (__n > 0) | 
 | 2585 |  { | 
 | 2586 |  pointer __fb = __f.__ptr_; | 
 | 2587 |  pointer __fe = *__f.__m_iter_ + __base::__block_size; | 
 | 2588 |  difference_type __bs = __fe - __fb; | 
 | 2589 |  if (__bs > __n) | 
 | 2590 |  { | 
 | 2591 |  __bs = __n; | 
 | 2592 |  __fe = __fb + __bs; | 
 | 2593 |  } | 
 | 2594 |  if (__fb <= __vt && __vt < __fe) | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 2595 |  __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_; | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2596 |  __r = _VSTD::move(__fb, __fe, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2597 |  __n -= __bs; | 
 | 2598 |  __f += __bs; | 
 | 2599 |  } | 
 | 2600 |  return __r; | 
 | 2601 | } | 
 | 2602 |  | 
 | 2603 | // move assign [__f, __l) to [__r - (__l-__f), __r) backwards. | 
 | 2604 | // If __vt points into [__f, __l), then add (__r - __l) to __vt. | 
 | 2605 | template <class _Tp, class _Allocator> | 
 | 2606 | typename deque<_Tp, _Allocator>::iterator | 
 | 2607 | deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r, | 
 | 2608 |  const_pointer& __vt) | 
 | 2609 | { | 
 | 2610 |  // as if | 
 | 2611 |  // while (__f != __l) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2612 |  // *--__r = _VSTD::move(*--__l); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2613 |  difference_type __n = __l - __f; | 
 | 2614 |  while (__n > 0) | 
 | 2615 |  { | 
 | 2616 |  --__l; | 
 | 2617 |  pointer __lb = *__l.__m_iter_; | 
 | 2618 |  pointer __le = __l.__ptr_ + 1; | 
 | 2619 |  difference_type __bs = __le - __lb; | 
 | 2620 |  if (__bs > __n) | 
 | 2621 |  { | 
 | 2622 |  __bs = __n; | 
 | 2623 |  __lb = __le - __bs; | 
 | 2624 |  } | 
 | 2625 |  if (__lb <= __vt && __vt < __le) | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 2626 |  __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_; | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2627 |  __r = _VSTD::move_backward(__lb, __le, __r); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2628 |  __n -= __bs; | 
 | 2629 |  __l -= __bs - 1; | 
 | 2630 |  } | 
 | 2631 |  return __r; | 
 | 2632 | } | 
 | 2633 |  | 
 | 2634 | // move construct [__f, __l) to [__r, __r + (__l-__f)). | 
 | 2635 | // If __vt points into [__f, __l), then add (__r - __f) to __vt. | 
 | 2636 | template <class _Tp, class _Allocator> | 
 | 2637 | void | 
 | 2638 | deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l, | 
 | 2639 |  iterator __r, const_pointer& __vt) | 
 | 2640 | { | 
 | 2641 |  allocator_type& __a = __base::__alloc(); | 
 | 2642 |  // as if | 
 | 2643 |  // for (; __f != __l; ++__r, ++__f, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2644 |  // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2645 |  difference_type __n = __l - __f; | 
 | 2646 |  while (__n > 0) | 
 | 2647 |  { | 
 | 2648 |  pointer __fb = __f.__ptr_; | 
 | 2649 |  pointer __fe = *__f.__m_iter_ + __base::__block_size; | 
 | 2650 |  difference_type __bs = __fe - __fb; | 
 | 2651 |  if (__bs > __n) | 
 | 2652 |  { | 
 | 2653 |  __bs = __n; | 
 | 2654 |  __fe = __fb + __bs; | 
 | 2655 |  } | 
 | 2656 |  if (__fb <= __vt && __vt < __fe) | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 2657 |  __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2658 |  for (; __fb != __fe; ++__fb, ++__r, ++__base::size()) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2659 |  __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2660 |  __n -= __bs; | 
 | 2661 |  __f += __bs; | 
 | 2662 |  } | 
 | 2663 | } | 
 | 2664 |  | 
 | 2665 | // move construct [__f, __l) to [__r - (__l-__f), __r) backwards. | 
 | 2666 | // If __vt points into [__f, __l), then subtract (__l - __r) from __vt. | 
 | 2667 | template <class _Tp, class _Allocator> | 
 | 2668 | void | 
 | 2669 | deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l, | 
 | 2670 |  iterator __r, const_pointer& __vt) | 
 | 2671 | { | 
 | 2672 |  allocator_type& __a = __base::__alloc(); | 
 | 2673 |  // as if | 
 | 2674 |  // for (iterator __j = __l; __j != __f;) | 
 | 2675 |  // { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2676 |  // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2677 |  // --__base::__start_; | 
 | 2678 |  // ++__base::size(); | 
 | 2679 |  // } | 
 | 2680 |  difference_type __n = __l - __f; | 
 | 2681 |  while (__n > 0) | 
 | 2682 |  { | 
 | 2683 |  --__l; | 
 | 2684 |  pointer __lb = *__l.__m_iter_; | 
 | 2685 |  pointer __le = __l.__ptr_ + 1; | 
 | 2686 |  difference_type __bs = __le - __lb; | 
 | 2687 |  if (__bs > __n) | 
 | 2688 |  { | 
 | 2689 |  __bs = __n; | 
 | 2690 |  __lb = __le - __bs; | 
 | 2691 |  } | 
 | 2692 |  if (__lb <= __vt && __vt < __le) | 
| Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 | [diff] [blame] | 2693 |  __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2694 |  while (__le != __lb) | 
 | 2695 |  { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2696 |  __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2697 |  --__base::__start_; | 
 | 2698 |  ++__base::size(); | 
 | 2699 |  } | 
 | 2700 |  __n -= __bs; | 
 | 2701 |  __l -= __bs - 1; | 
 | 2702 |  } | 
 | 2703 | } | 
 | 2704 |  | 
 | 2705 | template <class _Tp, class _Allocator> | 
 | 2706 | typename deque<_Tp, _Allocator>::iterator | 
 | 2707 | deque<_Tp, _Allocator>::erase(const_iterator __f) | 
 | 2708 | { | 
 | 2709 |  difference_type __n = 1; | 
 | 2710 |  iterator __b = __base::begin(); | 
 | 2711 |  difference_type __pos = __f - __b; | 
 | 2712 |  iterator __p = __b + __pos; | 
 | 2713 |  allocator_type& __a = __base::__alloc(); | 
 | 2714 |  if (__pos < (__base::size() - 1) / 2) | 
 | 2715 |  { // erase from front | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2716 |  _VSTD::move_backward(__b, __p, _VSTD::next(__p)); | 
 | 2717 |  __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2718 |  --__base::size(); | 
 | 2719 |  ++__base::__start_; | 
 | 2720 |  if (__front_spare() >= 2 * __base::__block_size) | 
 | 2721 |  { | 
 | 2722 |  __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); | 
 | 2723 |  __base::__map_.pop_front(); | 
 | 2724 |  __base::__start_ -= __base::__block_size; | 
 | 2725 |  } | 
 | 2726 |  } | 
 | 2727 |  else | 
 | 2728 |  { // erase from back | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2729 |  iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p); | 
 | 2730 |  __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2731 |  --__base::size(); | 
 | 2732 |  if (__back_spare() >= 2 * __base::__block_size) | 
 | 2733 |  { | 
 | 2734 |  __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 
 | 2735 |  __base::__map_.pop_back(); | 
 | 2736 |  } | 
 | 2737 |  } | 
 | 2738 |  return __base::begin() + __pos; | 
 | 2739 | } | 
 | 2740 |  | 
 | 2741 | template <class _Tp, class _Allocator> | 
 | 2742 | typename deque<_Tp, _Allocator>::iterator | 
 | 2743 | deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l) | 
 | 2744 | { | 
 | 2745 |  difference_type __n = __l - __f; | 
 | 2746 |  iterator __b = __base::begin(); | 
 | 2747 |  difference_type __pos = __f - __b; | 
 | 2748 |  iterator __p = __b + __pos; | 
 | 2749 |  if (__n > 0) | 
 | 2750 |  { | 
 | 2751 |  allocator_type& __a = __base::__alloc(); | 
 | 2752 |  if (__pos < (__base::size() - __n) / 2) | 
 | 2753 |  { // erase from front | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2754 |  iterator __i = _VSTD::move_backward(__b, __p, __p + __n); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2755 |  for (; __b != __i; ++__b) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2756 |  __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2757 |  __base::size() -= __n; | 
 | 2758 |  __base::__start_ += __n; | 
 | 2759 |  while (__front_spare() >= 2 * __base::__block_size) | 
 | 2760 |  { | 
 | 2761 |  __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size); | 
 | 2762 |  __base::__map_.pop_front(); | 
 | 2763 |  __base::__start_ -= __base::__block_size; | 
 | 2764 |  } | 
 | 2765 |  } | 
 | 2766 |  else | 
 | 2767 |  { // erase from back | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2768 |  iterator __i = _VSTD::move(__p + __n, __base::end(), __p); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2769 |  for (iterator __e = __base::end(); __i != __e; ++__i) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2770 |  __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2771 |  __base::size() -= __n; | 
 | 2772 |  while (__back_spare() >= 2 * __base::__block_size) | 
 | 2773 |  { | 
 | 2774 |  __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 
 | 2775 |  __base::__map_.pop_back(); | 
 | 2776 |  } | 
 | 2777 |  } | 
 | 2778 |  } | 
 | 2779 |  return __base::begin() + __pos; | 
 | 2780 | } | 
 | 2781 |  | 
 | 2782 | template <class _Tp, class _Allocator> | 
 | 2783 | void | 
 | 2784 | deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) | 
 | 2785 | { | 
 | 2786 |  iterator __e = __base::end(); | 
 | 2787 |  difference_type __n = __e - __f; | 
 | 2788 |  if (__n > 0) | 
 | 2789 |  { | 
 | 2790 |  allocator_type& __a = __base::__alloc(); | 
 | 2791 |  iterator __b = __base::begin(); | 
 | 2792 |  difference_type __pos = __f - __b; | 
 | 2793 |  for (iterator __p = __b + __pos; __p != __e; ++__p) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2794 |  __alloc_traits::destroy(__a, _VSTD::addressof(*__p)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2795 |  __base::size() -= __n; | 
 | 2796 |  while (__back_spare() >= 2 * __base::__block_size) | 
 | 2797 |  { | 
 | 2798 |  __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 
 | 2799 |  __base::__map_.pop_back(); | 
 | 2800 |  } | 
 | 2801 |  } | 
 | 2802 | } | 
 | 2803 |  | 
 | 2804 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 2805 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2806 | void | 
 | 2807 | deque<_Tp, _Allocator>::swap(deque& __c) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 2808 |  _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || | 
 | 2809 |  __is_nothrow_swappable<allocator_type>::value) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2810 | { | 
 | 2811 |  __base::swap(__c); | 
 | 2812 | } | 
 | 2813 |  | 
 | 2814 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 422a53f | 2010-09-21 21:28:23 | [diff] [blame] | 2815 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2816 | void | 
| Howard Hinnant | a12beb3 | 2011-06-02 16:10:22 | [diff] [blame] | 2817 | deque<_Tp, _Allocator>::clear() _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2818 | { | 
 | 2819 |  __base::clear(); | 
 | 2820 | } | 
 | 2821 |  | 
 | 2822 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2823 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2824 | bool | 
 | 2825 | operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 
 | 2826 | { | 
 | 2827 |  const typename deque<_Tp, _Allocator>::size_type __sz = __x.size(); | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2828 |  return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2829 | } | 
 | 2830 |  | 
 | 2831 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2832 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2833 | bool | 
 | 2834 | operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 
 | 2835 | { | 
 | 2836 |  return !(__x == __y); | 
 | 2837 | } | 
 | 2838 |  | 
 | 2839 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2840 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2841 | bool | 
 | 2842 | operator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 
 | 2843 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 2844 |  return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2845 | } | 
 | 2846 |  | 
 | 2847 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2848 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2849 | bool | 
 | 2850 | operator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 
 | 2851 | { | 
 | 2852 |  return __y < __x; | 
 | 2853 | } | 
 | 2854 |  | 
 | 2855 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2856 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2857 | bool | 
 | 2858 | operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 
 | 2859 | { | 
 | 2860 |  return !(__x < __y); | 
 | 2861 | } | 
 | 2862 |  | 
 | 2863 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2864 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2865 | bool | 
 | 2866 | operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 
 | 2867 | { | 
 | 2868 |  return !(__y < __x); | 
 | 2869 | } | 
 | 2870 |  | 
 | 2871 | template <class _Tp, class _Allocator> | 
| Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 | [diff] [blame] | 2872 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2873 | void | 
 | 2874 | swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y) | 
| Howard Hinnant | 0a612b0 | 2011-06-02 20:00:14 | [diff] [blame] | 2875 |  _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 2876 | { | 
 | 2877 |  __x.swap(__y); | 
 | 2878 | } | 
 | 2879 |  | 
 | 2880 | _LIBCPP_END_NAMESPACE_STD | 
 | 2881 |  | 
 | 2882 | #endif // _LIBCPP_DEQUE |